Simple Rest API With SpringBoot, Postgres and Docker

1. Create SpringBoot Application

2. SpringBoot Rest API

application.properties
embedded tomcat server

3. Dockerize SpringBoot Application

FROM openjdk:8
ADD target/first-0.0.1-SNAPSHOT.jar first-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "first-0.0.1-SNAPSHOT.jar"]

4. Use Postgres docker

docker hub
docker pull postgres:9.5

5. Use docker-compose

version: "3"
services:
postgres:
image:
postgres:0.1
network_mode: bridge
container_name: postgres
volumes:
- postgres-data:/var/lib/postgresql/data
expose:
- 5432
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=docker
- POSTGRES_USER=docker
- POSTGRES_DB=docker
restart: unless-stopped
# This is my rest api app*****************************************
myfirstapp:
image:
myfirst:0.1
network_mode: bridge
container_name: myfirst
expose:
- 8080
ports:
- 8081:8080
volumes:
- /home/pramod/Desktop:/var/tmp
restart: unless-stopped
volumes:
postgres-data:
docker-compose up

6. logs

logging.file = /var/tmp/mylog.log
volumes:
- /home/pramod/Desktop:/var/tmp

7. Rest APIs

8. Check The Entities

docker exec -it postgres /bin/bash
psql -d docker

9. Resources

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store