All tools
development
Docker Compose cheatsheet
Copy common Docker Compose v2 commands and a minimal compose file.
Project lifecycle
Docker Compose v2 command patterns.
- docker compose up
- Create and start services in the foreground.
- docker compose up -d
- Create and start services in the background.
- docker compose down
- Stop and remove containers and default networks.
- docker compose restart
- Restart all services in the project.
Build and pull
Docker Compose v2 command patterns.
- docker compose build
- Build or rebuild service images.
- docker compose up --build
- Build images before starting containers.
- docker compose pull
- Pull service images from their registries.
Services
Docker Compose v2 command patterns.
- docker compose ps
- List project containers and their status.
- docker compose logs -f service
- Follow logs for one service.
- docker compose exec service sh
- Open a shell in a running service container.
- docker compose run --rm service command
- Run a one-off command and remove the container.
Configuration
Docker Compose v2 command patterns.
- docker compose config
- Render and validate the merged compose configuration.
- docker compose -f compose.yml -f compose.override.yml up
- Start with multiple compose files merged in order.
- docker compose --profile debug up
- Enable services assigned to the debug profile.
Cleanup
Docker Compose v2 command patterns.
- docker compose down -v
- Stop containers and remove named volumes declared by the project.
- docker compose rm
- Remove stopped service containers.
Minimal compose file
A compact service with image, ports, environment, and volumes.
services:
web:
image: nginx:alpine
ports:
- "8080:80"
environment:
NGINX_HOST: localhost
volumes:
- ./site:/usr/share/nginx/html:ro