Catalog / Docker Compose Cheatsheet
Docker Compose Cheatsheet
A comprehensive guide to Docker Compose, covering essential commands, configurations, and best practices for defining and managing multi-container Docker applications.
Basic Concepts & Setup
What is Docker Compose?
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. |
Key benefits include:
|
Installation
Docker Compose is now integrated into Docker Desktop. Ensure Docker Desktop is installed and running. For standalone installation (if needed):
|
Docker Compose File (docker-compose.yml)
The
|
Essential Commands
Lifecycle Management
|
Builds, (re)creates, starts, and attaches to containers for all services defined in the Flags: |
|
Stops and removes containers, networks, volumes, and images created by |
|
Starts existing containers. |
|
Stops running containers without removing them. |
|
Restarts all services. |
Service Interaction
|
Lists the status of the containers. |
|
View output from the containers. Service can be specified |
|
Execute a command in a running container. Example: |
|
Run a one-off command against a service. Example: |
Configuration Inspection
|
Validate and view the Compose file configuration. Useful for verifying your setup. |
|
Displays the Docker Compose version. |
Configuration Options
Build Configuration
Use the
|
|
Image Configuration
Specify a pre-built image using the
|
You can also specify a private registry:
|
Port Mapping
Expose ports from the container to the host machine:
|
Use
|
Volumes
Share directories or volumes between the host and containers.
|
Environment Variables
Set environment variables for services.
|
|
Advanced Configuration
Dependencies & Health Checks
Define service dependencies and health checks to ensure proper startup order and service availability.
|
|
Networks
Create custom networks for inter-container communication.
|
|
Extending Services
Use
|
|
Resource Limits
Limit the resources a container can use.
|
|