Technical Mid Level

How do you structure a Docker Compose file for a multi-service application? Discuss service dependencies, health checks, and environment management.

Quick Tip

Show production awareness: "I use healthcheck on the database so the app service waits until Postgres is actually accepting connections, not just until the container starts. depends_on alone is not enough."

What good answers include

Compose defines services, networks, and volumes in a YAML file. Service dependencies: depends_on controls startup order but does not wait for readiness — use healthcheck with condition: service_healthy for true dependency management. Environment: use env_file for shared variables, environment for service-specific overrides, and .env for Compose variable substitution. Best practices: one service per container, custom networks for isolation, named volumes for persistence, and profiles for optional services (debug tools, admin panels). Strong candidates discuss: Compose override files (docker-compose.override.yml) for dev-specific config, the watch feature for live reloading, resource limits (deploy.resources), and build caching with cache_from.

What interviewers are looking for

Tests practical multi-container development. Candidates who have race conditions because they rely on depends_on without health checks are missing a critical pattern. Those who structure Compose files with proper health checks, networks, and override files manage complex stacks reliably.

← All Docker questions