Start the complete stack
docker compose up --build
This command builds the Java application image and starts two services:
db: PostgreSQL 16 on host port5432, databaseidentity_db.app: the packaged Spring Boot service on host port8080.
Use detached mode when terminal logs are not needed continuously:
docker compose up --build -d
Readiness and startup order
The database health check runs pg_isready against identity_db. Compose starts the application only after PostgreSQL reports healthy through depends_on.condition: service_healthy.
After the application starts, Flyway applies migrations and Hibernate validates the schema. Inspect state and logs with:
docker compose ps
docker compose logs -f db
docker compose logs -f app
Environment variables
| Variable | Default | Effect |
|---|---|---|
DB_USERNAME | postgres | Configures the PostgreSQL user and the application's datasource username. |
DB_PASSWORD | postgres | Configures the PostgreSQL password and the application's datasource password. |
Compose injects jdbc:postgresql://db:5432/identity_db into the application. The hostname is the Compose service name, so it differs from the localhost URL used by a Maven development run.
The defaults are local development credentials. Use environment-specific secret management outside this portfolio Compose file for any real deployment.
Stop and clean up
Stop containers while keeping them available for a later restart:
docker compose stop
docker compose start
Remove the containers and Compose network:
docker compose down
The current Compose file does not define a persistent database volume. Removing the database container also removes its local database state.
Common Docker checks
- Run
docker compose configto validate interpolation and structure. - Run
docker compose build appto validate the application image without starting services. - Check that ports
5432and8080are free before startup. - Use
docker compose logsbefore rebuilding repeatedly; migration or credential errors are usually visible there.
See Troubleshooting for daemon, port, Flyway, and startup failures.