Docker Compose Cheat Sheet
The most important Docker Compose keywords and commands explained briefly, for running multiple services from a single file.
Last updated: September 1, 2026
Basic file structure
services:Top level block, lists all services in the filemy-service:Freely chosen name of a single serviceimage:Ready made image from a registry to usebuild:Builds a custom image from a Dockerfile insteadcontainer_name:Fixed, custom name instead of an automatically assigned oneNetwork and ports
ports:Connects a container port with a host portnetworks:Defines which Docker networks the service connects tonetwork_mode: hostUses the host's network directly, without a Docker network in betweenexpose:Opens a port only for other containers, not to the outsideData and environment
volumes:Permanently connects a host folder with the containerenvironment:Sets environment variables directly in the fileenv_file:Loads environment variables from a separate file insteadBehavior and dependencies
restart:Defines when a container restarts automaticallydepends_on:Starts a service only after another one has startedhealthcheck:Regularly checks whether a service is actually workingrestart: unless-stoppedRestarts automatically unless deliberately stoppedTerminal commands
docker compose up -dStarts all services in the backgrounddocker compose downStops and removes all services in the filedocker compose buildRebuilds the images defined under build:docker compose logs -fShows all services' logs continuouslyChecking and managing
docker compose psShows the status of all services in this filedocker compose restartRestarts all services in the filedocker compose configChecks the file for errors and shows the final configurationdocker compose pullDownloads newer versions of the images in useWorth a look
A simple example
Here's what a very simple Compose file with a single service looks like.
| docker-compose.yml | |
|---|---|
services: | Start of the services block |
webserver: | Name of the service, freely chosen here |
image: nginx:latest | Uses the ready made, official Nginx image |
ports: | Start of the port mapping |
- "8080:80" | Host port 8080 points to container port 80 |
restart: unless-stopped | Restarts automatically unless deliberately stopped |
Indentation in a YAML file, like the one Docker Compose uses, is crucial, it defines what belongs to which block. A single misplaced space can already cause an error.