This project demonstrates how to containerize a Spring Boot application using Docker and Docker Compose, with a PostgreSQL database.
- Docker Desktop (with Docker Compose)
- Java 21+
- Maven
git clone <repository-url>
Create a .env file in the project root with the following content:
POSTGRES_DB=testDB
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgresYou can change these values as needed, but make sure they match the configuration in application.properties and docker-compose.yaml.
docker compose up --build- The Spring Boot app will be available at http://localhost:8085
- PostgreSQL will be available at
localhost:5432
docker compose downDockerfile- Multi-stage build for Spring Boot appdocker-compose.yaml- Defines services for the app and PostgreSQLinit/init.sql- SQL script to initialize the databasesrc/- Application source code
- The application uses environment variables for database configuration.
- The database is initialized with sample data from
init/init.sql.
That's all!