Docker Compose is useful for starting a group of services with one declared configuration. It does not guarantee that the services are correctly ordered or ready; applications still need health checks, retries, and clear startup behavior.
Describe the actual dependency graph
Give each service a stable name and expose only the ports developers need on the host. Use service DNS names for container-to-container connections rather than
localhostPersist database data in a named volume and make reset commands explicit. Keep secrets out of committed Compose files; use a local ignored environment file or a secret manager appropriate to the deployment. Separate development conveniences such as source mounts and hot reload from production image settings.
Make startup and shutdown observable
Use restart policies deliberately, but do not rely on them to cure a crash loop. Inspect container logs and exit codes when a service repeatedly restarts. Ensure processes handle termination signals and close database or queue connections cleanly. Avoid excessive health-check frequency that can add load or mark a slow but healthy service as dead.
Document the supported profile, expected ports, data persistence, and reset procedure. Test a cold start, a service restart, and a restart after the database volume already exists. Compose is a reproducible local environment when dependencies and operational assumptions are written down.
Use readiness to express a real dependency
In Docker Compose, a dependency can start before it is ready to answer requests. Configure a health check for a service such as PostgreSQL, and use depends_on with condition service_healthy when a dependent service needs to wait for it. An application still needs a bounded retry path for a dependency that goes down after startup. Docker Compose startup order
Name database volumes so a normal image update can reuse data. Give local and production deployments different configuration and credentials. Use docker compose config --quiet to validate syntax and references without printing the fully resolved configuration. Then inspect the running service status and test the actual application endpoint. A Compose configuration describes the desired services, while a readiness check shows whether a dependency is accepting work.
Worked example
Run from the directory containing your Compose configuration, with the intended environment file. Configuration validation does not establish service health, and logs may contain sensitive data.
shdocker compose config --quiet docker compose ps docker compose logs --tail=50 web




Community
Discussion
Loading comments…