Container runtime

Docker usage

Start the complete application stack, understand readiness behavior, and manage the local containers deliberately.

Start the complete stack

docker compose up --build

This command builds the Java application image and starts two services:

  • db: PostgreSQL 16 on host port 5432, database identity_db.
  • app: the packaged Spring Boot service on host port 8080.

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

VariableDefaultEffect
DB_USERNAMEpostgresConfigures the PostgreSQL user and the application's datasource username.
DB_PASSWORDpostgresConfigures 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 config to validate interpolation and structure.
  • Run docker compose build app to validate the application image without starting services.
  • Check that ports 5432 and 8080 are free before startup.
  • Use docker compose logs before rebuilding repeatedly; migration or credential errors are usually visible there.

See Troubleshooting for daemon, port, Flyway, and startup failures.