Docker Compose Cheat Sheet
Essential Docker Compose CLI commands and YAML syntax for defining and running multi-container applications locally.
2 PagesBeginnerJan 25, 2026
CLI Basics
Core commands to manage a Compose project.
bash
docker compose up # Create and start all servicesdocker compose up -d # Start in detached modedocker compose down # Stop and remove containers/networksdocker compose down -v # Also remove named volumesdocker compose ps # List project containersdocker compose logs -f web # Tail logs for the 'web' servicedocker compose exec web sh # Shell into a running servicedocker compose build # Build/rebuild imagesdocker compose restart web # Restart one service
compose.yaml Structure
A typical multi-service application definition.
yaml
services: web: build: . ports: - "3000:3000" environment: - NODE_ENV=production depends_on: - db volumes: - ./src:/app/src db: image: postgres:15 environment: POSTGRES_PASSWORD: secret volumes: - db-data:/var/lib/postgresql/datavolumes: db-data:
Key Directives
Common top-level and service-level keys.
- depends_on- Controls startup order; use condition: service_healthy to wait for a healthcheck
- healthcheck- Defines test/interval/retries to determine when a service is 'healthy'
- networks- Custom networks for controlling which services can reach each other
- env_file- Loads environment variables from a .env-style file into the service
- profiles- Tags services so they only start when a matching --profile flag is passed
- extends / include- Reuse configuration across compose files or include another compose file
Multi-file / Override
Layer environment-specific overrides on a base file.
bash
# docker-compose.override.yml is merged automatically with docker-compose.ymldocker compose -f docker-compose.yml -f docker-compose.prod.yml up -d# Validate merged config without starting anythingdocker compose config
Pro Tip
Use depends_on with condition: service_healthy plus a real healthcheck instead of sleep hacks, so dependent services only start once the database is actually ready to accept connections.
Was this cheat sheet helpful?
Explore Topics
#DockerCompose#DockerComposeCheatSheet#DevOps#Beginner#CLIBasics#ComposeYamlStructure#KeyDirectives#MultiFileOverride#Docker#CommandLine#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance