Skip to content

This is a Springboot application connecting to PostgreSQL run on docker compose with pgadmin

Notifications You must be signed in to change notification settings

Johny-Ch/springboot-postgres-pgadmin-docker

Repository files navigation

springboot-postgres-pgadmin-docker

This is a Springboot application running on docker

  • Contains a GET & POST APIs to create and read employees with first & last name fields
    • POST API can be used to create employee with fields "firstName" & "lastName"
    • GET API can be used to get all employees stored
  • This application connects to PostgreSQL database that will be running as a containerized service on docker
  • This application also builds and deploys pgadmin as a container on docker that will help us in browsing our postgres database
    • pgAdmin is a commonly used database management tool in the PostgresDB community. It simplifies the creation, maintenance, and use of database objects by offering a clean and intuitive user interface.

Environment

Prerequisites

  1. Download and install Docker Desktop
  2. Download and install IntelliJ IDEA Community (Free, open-source) here

Executing Project

  1. Clone the main branch of the project on to your working environment, clone url
  2. Open cloned project in Intellij
  3. Open docker-compose.yml file
  4. Execute all services by clicking on two green arrows at line 3 in docker-compose.yml file - aka docker-compose up Execute all services
  5. Verify if all the containers are up & running on you docker desktop, you see something like this
    • Screenshot of all containers running
    • All Containers Running
    • Screenshot of some containers not running
    • Some Containers Not Running
  6. If all containers are up & running, you can go ahead and create some data by calling the APIs below
        {
            "firstName": "Docker",
            "lastName": "Desktop"
        }
    
        {
            "id" : "1",
            "firstName": "Docker",
            "lastName": "Desktop"
        }
    

Ports

  1. Rest APIs will be running on port 18080
  2. PostgreSQL database will be running on port 5432
  3. pgAdmin will be running on port 5050

Accessing pgAdmin

pgAdmin is a commonly used database management tool in the PostgresDB community. It simplifies the creation, maintenance, and use of database objects by offering a clean and intuitive user interface.

  1. pgAdming takes time to boot up
  2. You monitor and confirm it's readiness by looking at the pgadming-container logs as below
    • This is how logs will look like when pgAdmin container is ready for usage This is how logs will look like when pgAdmin container is ready for usage
  3. We have preloaded the servers on to pgAdmin by using environment variable PGADMIN_SERVER_JSON_FILE and supplied servers here
  4. We are using default password as "changeme" to login to postgres database
  5. You can login to pgadming at http://localhost:5050/browser/ and browse as below

Browser pgAdming

PostgreSQL Username & Passwords

  • Username: postgres
  • Password: changeme

Dockerfiles

We have two docker files in this application

  1. Dockerfile-restapi
  2. Dockerfile-pgadmin

Dockerfile-restapi

This file is used to run the maven build by copying the src directory containing all the java code and pom.xml file The next section in this file loads JDK and copies the generated jar file as application.jar and then it is launched

Dockerfile-pgadmin

This file is used to load pgadmin docker image and copy the postgres-servers.json on to container at /pgadmin4/servers.json

Docker compose

The docker compose file contains 3 services

  1. restapi
  2. pgadmin
  3. postgres

restapi

This service will invoke the Dockerfile-restapi and is dependent on postgres We are supplying enviornment variables required for loading postgres database

pgadmin

This service will invoke the Dockerfile-pgadmin and is dependent on postgres We are supplying enviornment variables required for preloading servers

postgres

This service will load postgre image and start the container running postgres database

Docker Images

  1. springboot-postgres-pgadmin-docker
  2. pgadmin4
  3. postgres

Docker Images

References

About

This is a Springboot application connecting to PostgreSQL run on docker compose with pgadmin

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages