Cheatsheet: Docker Compose
Last updated 2026-09-26
Basic Commands
Start services in the foreground (build if needed)
Start services in the background (detached)
Rebuild images and start services
Stop and remove containers and the default network
Stop and remove containers, network, and named volumes
Stop services without removing them
Start previously-stopped services
Restart services
List containers for this project
Logs, Exec & One-off Commands
Follow logs for all services
Follow logs for one service, last 100 lines
Open a shell in a running service's container
Run a one-off command in a new container, then remove it
View resolved config after variable substitution and merges
List running processes per service
Building, Images & Cleanup
Build (or rebuild) images without starting containers
Build without using the Docker layer cache
Pull the latest images for all services
List images used by this project's containers
Remove stopped service containers
Remove containers, default network, and any orphaned containers
Scaling, Profiles & Multiple Compose Files
Run multiple instances of one service
Start only services tagged with a given profile (plus untagged ones)
Layer a second compose file on top of the base file (later files win)
Load environment variables from a specific .env-style file
compose.yml Syntax
A minimal compose.yml: two services, a named volume, and a dependency
build: — build from a local Dockerfile instead of a prebuilt image
ports: — map host:container ports
volumes: — named volumes vs. bind mounts
depends_on with condition: — wait for a dependency to actually be healthy