Docker · Containers in practice
What is Docker Compose and what is it good for?
Short answer
Compose defines a multi-container application in one YAML file and manages its lifecycle with a single command. It is excellent for local development and simple single-host deployments.
Compose describes services, networks, volumes and configuration. It creates a default network so services resolve each other by name, and it can build images as well as pull them. It is not a cluster orchestrator, but it is a reliable way to run an application stack on one machine.
services:
api:
build: .
ports:
- "8080:3000"
environment:
DATABASE_URL: postgres://app:secret@db:5432/app
depends_on:
db:
condition: service_healthy
db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app"]
interval: 5s
retries: 10
volumes:
pgdata:Where it fits
- Local development with a database, cache and queue
- Integration tests that need real dependencies
- Single-host deployments for small internal services
- A readable description of how services relate
depends_on with a health condition controls startup order, but it does not make an application resilient. Services should still retry connections and handle a dependency that restarts. For multi-node scheduling, rolling updates and self-healing, use an orchestrator.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Does depends_on wait for a service to be ready?
- 2How do services find each other in Compose?
- 3When would Compose stop being enough?
- 4How do you run a one-off command in a Compose service?
Say it in the interview
Compose describes a multi-container stack in YAML and manages it as one project. I use it for local development and integration tests because services resolve each other by name and a single command brings the stack up. I use a healthcheck with depends_on to control startup, but I still make the app retry, since startup order is not resilience.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Docker mock interview and get scored feedback on depth, clarity and confidence.