Skip to content
Ameen Abozaid
JNR-050

Docker Compose

  • 5 Lessons
  • 2 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Spring Boot + PostgreSQL local environment

Learn first

2 h of practice (estimate)

Learning outcomes

  1. Define a multi-service local environment (app, PostgreSQL, Keycloak) in compose.yaml.
  2. Use health checks and dependency conditions so services start in a usable order.
  3. Supply configuration through environment files without committing secrets.
  4. Use Spring Boot's Docker Compose support for development.

Lessons

  1. 01Compose files
  2. 02Health checks and startup order
  3. 03Environment and secrets
  4. 04Spring Boot's Compose integration
  5. 05Demo: one-command Shop stack

Lab and exercises

Lab

JNR-050-LAB1 · One-command Shop

Outcomes: 1–4 · Time: ~2 h docker compose up starts the whole stack (Shop, PostgreSQL, Keycloak) with seeded data, health checks, and env-file configuration. Write a README. Acceptance: a new teammate runs the stack in under 10 minutes using only the README.

Exercises (assessment: lab check)

IDOutcomeTask
JNR-050-EX011Write a compose.yaml with PostgreSQL (named volume) and the Shop app built from the Dockerfile.
JNR-050-EX021Add Keycloak and expose it on a host port; list which service names reach which.
JNR-050-EX032Add a pg_isready health check and make the app wait with service_healthy.
JNR-050-EX042Explain why the app can still fail even with service_healthy, and what the app should do about it.
JNR-050-EX053Move the database password to .env, add .env.example, and update .gitignore.
JNR-050-EX064Add the Spring Boot Docker Compose dependency and run the app from the IDE without starting Compose manually.
Show solutions
  • EX01 Services db (image: postgres:16, volumes: [pgdata:/var/lib/postgresql/data]) and app (build: ., ports: ["8080:8080"]), plus top-level volumes: pgdata:.
  • EX02 keycloak service with its image and ports; app reaches db:5432 and keycloak:8080 by service name; the browser uses the mapped host port.
  • EX03 healthcheck: test: ["CMD-SHELL","pg_isready -U postgres"] and depends_on: db: condition: service_healthy.
  • EX04 Healthy means ready at that moment; the database can restart later. The app should use connection retries (and a pool that recovers).
  • EX05 POSTGRES_PASSWORD: ${DB_PASSWORD}; .env.example has DB_PASSWORD=change-me; .gitignore lists .env.
  • EX06 Add spring-boot-docker-compose (verify the artifact and Boot version); starting the app launches the stack and wires the datasource.
  • Common mistakes (committed .env, depends_on without health) are checked in the lab.

Quiz

Outcomes: O1 compose files · O2 health checks · O3 environment and secrets · O4 Spring Boot integration.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1Which file defines a Compose stack?O1
  2. 2Services in one Compose project reach each other by:O1
  3. 3docker compose down -v also removes:O1
  4. 4Plain depends_on waits until the dependency:O2
  5. 5Which makes the app wait for a ready database?O2
  6. 6A Postgres health check commonly uses:O2
  7. 7Which should be committed?O3
  8. 8${DB_PASSWORD} in compose.yaml is filled from:O3
  9. 9Spring Boot's Compose support is meant for:O4
  10. 10What does it do on app start?O4

Practical part

Six exercises JNR-050-EX01 to EX06 plus the lab; the assessment is the lab check. Pass: quiz 8/10, at least five exercises correct, and a teammate starts the stack from the README in under 10 minutes.

Common mistakes

depends_on without health checks; committed .env files.

Assessment

Lab check.

Career relevance

The capstone's local environment requirement.

Type to search levels, phases, modules and lessons.