Docker Compose Cheat Sheet
A searchable reference of Docker Compose CLI commands and compose file keys and what each one does.
| Command or key | What it does |
|---|---|
docker compose up | Create and start every service defined in the compose file. |
docker compose up -d | Start all services in the background and return the terminal (detached mode). |
docker compose up --build | Rebuild service images before starting the containers. |
docker compose down | Stop and remove the containers and default network created by up. |
docker compose down -v | Stop everything and also delete named and anonymous volumes. |
docker compose start | Start existing stopped containers without recreating them. |
docker compose stop | Stop running containers but keep them for a later start. |
docker compose restart | Restart all service containers in the project. |
docker compose ps | List the project containers with their status and published ports. |
docker compose logs | Print the combined logs from all service containers. |
docker compose logs -f | Stream and follow new log output as it is produced. |
docker compose exec <service> <cmd> | Run a command inside a container that is already running. |
docker compose run <service> <cmd> | Start a one-off container for a service and run a command in it. |
docker compose build | Build or rebuild images for services that define a build section. |
docker compose pull | Download the latest images for services from their registry. |
docker compose config | Validate and print the fully merged, resolved configuration. |
docker compose kill | Force-stop service containers by sending them SIGKILL. |
docker compose rm | Remove stopped service containers from the project. |
docker compose images | List the images used by the project containers. |
docker compose top | Show the running processes inside each service container. |
services | Top-level map where each container in the app is defined by a service name. |
image | Service key naming the image to pull and run for the container. |
build | Service key that builds an image from a Dockerfile instead of pulling one. |
build.context | Path to the directory sent to the builder as the build context. |
command | Override the default command the container runs at start. |
entrypoint | Override the image entrypoint that wraps the command. |
container_name | Set a fixed container name instead of the generated project name. |
restart | Restart policy: no, always, on-failure, or unless-stopped. |
depends_on | List services that must start before this one to control start order. |
environment | Set environment variables inside the container as a list or a map. |
env_file | Load environment variables into the container from one or more files. |
ports | Publish container ports to the host using HOST:CONTAINER mappings. |
expose | Mark ports as reachable by linked services without publishing to the host. |
volumes | Mount host paths or named volumes into the container filesystem. |
volumes (named volume) | Reference a Compose-managed named volume with the name:/path form. |
working_dir | Set the working directory for commands run inside the container. |
user | Run the container process as a given username or UID. |
labels | Attach arbitrary metadata labels to the container. |
networks | Attach a service to one or more named networks. |
networks (aliases) | Give a service extra DNS names on a network through aliases. |
links | Legacy way to reach another service by name, now superseded by networks. |
extra_hosts | Add custom host-to-IP entries to the container hosts file. |
ports (HOST:CONTAINER) | Map a host port to a container port, such as 8080:80. |
healthcheck | Define a command Compose runs to test that a container is healthy. |
deploy.replicas | Number of identical container copies to run for a service. |
profiles | Assign a service to named profiles so it starts only when a profile is active. |
volumes (top-level) | Top-level key that declares named volumes shared across services. |
networks (top-level) | Top-level key that declares custom networks for the project. |
extends | Reuse configuration from another service or file to avoid repetition. |
x-* extension fields | Custom top-level keys starting with x- that Compose ignores, handy with anchors. |
scale | Set how many containers run for a service, as with up --scale. |
No commands or keys match your search.
Runs entirely in your browser. Nothing you type is sent anywhere; open DevTools and watch the Network tab to verify zero requests.
What this tool does
This is a searchable quick reference for Docker Compose: both the
docker compose CLI commands you run in the terminal and the keys you
write in a compose file. Each row pairs the exact command or key with a
plain-English note on what it does. Type in the filter box to search across both
columns, or tap a category button to focus on the CLI, services, config,
networking, or advanced keys. The whole list is built into the page, so it works
offline and sends nothing anywhere.
How to use it
Start typing in the Filter box. Entering up surfaces
every start command, entering volumes shows the mounting and
persistence keys, and entering depends_on jumps straight to start-order
control. The category buttons (CLI, Services, Config, Networking,
Advanced) narrow the table to one group and combine with the text filter, so you can
pick Config and type ports to see only the port keys. Clear the box to
see the full sheet again.
Common use cases
- Recalling the exact flag for a command you use rarely, like
docker compose up --buildordown -v. - Copying a compose file key such as
healthcheckordepends_onwithout hunting through the docs. - Checking whether a variable belongs under
environmentorenv_file. - Reminding yourself that
down -vdeletes named volumes before you run it. - Learning the difference between publishing a port with
portsand only exposing it withexpose.
Common pitfalls
- Losing data with down -v. Plain
docker compose downkeeps your named volumes, but adding-vdeletes them. Leave off-vunless you truly want a clean slate. - Expecting depends_on to wait for readiness. By default
depends_ononly waits for the dependency container to start, not for the service inside to accept connections. Pair it with ahealthcheckand theservice_healthycondition when you need real readiness. - Confusing ports with expose.
portspublishes a port to the host inHOST:CONTAINERform, whileexposeonly makes it reachable by other services on the same network. - Forgetting variable interpolation. Values written as
${VARIABLE}in the compose file are filled in from your shell or a.envfile, so a missing variable can quietly resolve to an empty string.
Frequently asked questions
- What is Docker Compose?
- Docker Compose is a tool for defining and running multi-container applications from a single YAML file, usually named compose.yaml or docker-compose.yml. You describe your services, networks, and volumes once, then bring the whole stack up or down with one command. Compose v2 ships as the docker compose subcommand built into the Docker CLI, replacing the older standalone docker-compose binary.
- What is the difference between docker compose up and up -d?
- docker compose up starts your services and streams their combined logs to the terminal, so the session stays attached and stopping it with Ctrl+C stops the containers. Adding -d runs them in detached mode: Compose starts everything in the background and returns your prompt, leaving the containers running until you call docker compose down or stop. Use plain up while developing so you can watch output, and up -d for services you want to keep running.
- What does depends_on do?
- depends_on lists other services that must be started before the current one, so Compose controls the startup order and starts dependencies first. By default it only waits for the dependency container to start, not for the app inside to be ready to accept connections. To wait for readiness you combine depends_on with a healthcheck and the condition service_healthy form, which holds the dependent service until the health check passes.
- How do I pass environment variables to a service?
- You can pass environment variables a few ways. The environment key sets them inline as a list or a map under a service. The env_file key loads them in bulk from one or more files such as .env. You can also reference host or .env values inside compose.yaml using the ${VARIABLE} interpolation syntax, which keeps secrets and per-machine settings out of the committed file.
- How do volumes persist data between restarts?
- Named volumes persist data independently of any container, so removing and recreating a service keeps its data intact. You declare a volume under the top-level volumes key and mount it into a service with the volume_name:/path form, and Docker stores it outside the container writable layer. Anonymous and bind-mounted paths also survive restarts, but only a named volume is easy to reuse and back up. Note that docker compose down -v deletes named volumes, so avoid -v when you want to keep the data.
- Does this cheat sheet send anything to a server?
- No, it stays in your browser. The full command and key list is baked into the page at build time, and the search and category filters run locally in JavaScript, so nothing you type leaves your device. Open your browser DevTools and watch the Network tab while you filter to confirm there are zero requests.
Cite this tool
For academic, journalistic, or technical references. Pick a format:
Citations use 2026 as the publication year. Access date is left as a fillable placeholder where the citation style expects one.