Docker Compose YAML and CLI Cheat Sheet
This quick reference guide summarizes commonly used Docker Compose configuration keys and CLI commands.
1. Core YAML Service Keys
| Key | Purpose | Example |
image | Use a pre-built registry image | image: postgres:16 |
build | Build image from local Dockerfile | build: ./app |
ports | Map host port to container port | ports: ["3000:3000"] |
environment | Inject environment variables | environment: [KEY=value] |
volumes | Mount volumes or bind mounts | volumes: [data:/app/data] |
depends_on | Define container start order | depends_on: [db] |
networks | Connect to declared networks | networks: [private-net] |
2. Compose CLI Commands
# Start all services (rebuild images first)
docker compose up -d --build
# Stop and remove containers plus networks
docker compose down
# Stop and remove containers, networks, and volumes
docker compose down -v
# View logs from all services in real time
docker compose logs -f
# List current service statuses
docker compose ps
# Run a command inside a running service container
docker compose exec service_name bashPublished on Last updated: