Day 4 – Docker Compose Orchestration
Today's Focus
Write a Docker Compose file that orchestrates your full multi-service stack for local development.
Tasks
- Write a
docker-compose.ymlthat defines three services:db(PostgreSQL),backend(your Node/Python API), andfrontend(nginx serving static files). Use service names as hostnames for inter-service communication. - Configure
depends_onwith a health check condition:dbservice should have ahealthcheckusingpg_isready, andbackendshould usecondition: service_healthyso it waits until Postgres is ready. - Use a
.envfile for all secrets and configuration:POSTGRES_PASSWORD,DB_NAME,API_PORT. Reference them indocker-compose.ymlwith${POSTGRES_PASSWORD}. Never hard-code credentials in the Compose file. - Add a
volumessection for Postgres data persistence and a bind-mount overlay for your backend source code in development mode (so you can usenodemonor hot-reload without rebuilding the image). - Define a development override: create
docker-compose.override.ymlthat mounts source code and enables hot-reload. The basedocker-compose.ymlshould be production-safe (no source mounts). Run withdocker compose up(picks up the override automatically) and compare todocker compose -f docker-compose.yml up(production mode). - Run
docker compose up -d, thendocker compose logs -f backendto tail logs. Rundocker compose psto see service health. Usedocker compose exec backend shto shell into the running backend container.