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

How to Install and Configure Icinga2 Monitoring Tool on Ubuntu 16.04

Dynamic theming in Vaadin Flow

Fake and free Bypass-on-Cookie - with CloudFlare edge cache workers for Wordpress

Day 5: Retrospective

Phantom of the Coroutine

Downsampling and Exporting Stackdriver Monitoring Data

Rest Assured Tutorial | Day 1 | Client Server Architecture Explained (API Testing Basics)

5 Major Mobile App Budgeting Mistakes

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

Eureka Server and API gateway

Spring boot Initializr

Setup a Kafka broker on Docker

Spring boot with Mongo DB easy setup