Docker Compose is a tool that allows developers to define and run multi-container Docker applications. It simplifies the process of managing multiple containers by providing a way to define and configure them in a single file.
With Docker Compose, developers can define the services that make up their application, including their dependencies, and then run them all together with a single command. This makes it easy to test and deploy applications in a consistent and repeatable way.
This cheat sheet provides an extensive list of Docker Compose commands and their descriptions.
Table of Contents
General Commands
Command Description docker-compose up
Builds, (re)creates, starts, and attaches to containers for a service. docker-compose down
Stops and removes containers, networks, images, and volumes. docker-compose build
Builds or rebuilds services. docker-compose start
Starts existing containers for a service. docker-compose stop
Stops running containers without removing them. docker-compose restart
Restarts containers. docker-compose pause
Pauses running containers of a service. docker-compose unpause
Unpauses paused containers of a service. docker-compose ps
Lists containers. docker-compose logs
Shows logs for a service. docker-compose exec
Runs a command in a running container. docker-compose run
Runs a one-time command against a service.
Service Configuration
Command Description docker-compose config
Validates and displays the Compose file. docker-compose version
Shows the Docker Compose version. docker-compose images
Lists images used by the Compose file. docker-compose top
Shows the running processes of a container. docker-compose events
Streams real-time events from containers. docker-compose kill
Forces running containers to stop. docker-compose rm
Removes stopped containers. docker-compose pull
Pulls images for services. docker-compose push
Pushes images for services.
Environment Variables
Command Description docker-compose config --env
Displays the environment variables used in the Compose file. docker-compose up -e
Sets environment variables. docker-compose up --env-file
Loads environment variables from a file.
Volumes
Command Description docker-compose volume ls
Lists volumes. docker-compose volume create
Creates a volume. docker-compose volume rm
Removes a volume. docker-compose volume inspect
Displays detailed information about a volume.
Networking
Command Description docker-compose network ls
Lists networks. docker-compose network create
Creates a network. docker-compose network rm
Removes a network. docker-compose network inspect
Displays detailed information about a network.
Scaling
Command Description docker-compose up --scale
Scales a service to a specified number of containers. docker-compose scale
Scales a service to a specified number of containers.
Deployment
Command Description docker-compose config --services
Lists services in the Compose file. docker-compose config --volumes
Lists volumes in the Compose file. docker-compose config --networks
Lists networks in the Compose file. docker-compose config --hash
Displays the hash of the Compose file. docker-compose config --quiet
Displays only the hash of the Compose file.
References