Simple Rest API With SpringBoot, Postgres and Docker

  1. SpringBoot
  2. Postgres
  3. Docker
  4. Docker compose

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

1. Save employee

2. Get all employees

3. Get employee by id

4. Display error when trying to get not existing id

5. Update employee

6. Delete employee

8. Check The Entities

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

9. Resources

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Effortless improvement in the art of programming

Setup a container cluster on AWS with Terraform provision on VPC -1

Auto-Updating Your Github Profile With Python

Evrone at RnDTechConf: Cinderella, Master Yoda, and Unicorns

How to setup a project using pyenv?

Multiprocessing with Pandas: 46 to 95% Faster Dataframe Enhancements

Performance Testing: Self-built Databases vs. ApsaraDB for RDS

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
Pramod Shehan

Pramod Shehan

More from Medium

Identity Management with AWS Cognito in SpringBoot Application.

Simple CRUD with Spring Boot

H2 In-memory Database

Using Java Faker lib to populate data on DynamoDB employing AWS-SDK