Docker Compose is a tool that runs an app made of several containers from one file. You write the containers, their ports, their storage and their settings in a file named compose.yaml. Then one command, docker compose up -d, creates and starts them all, and docker compose down stops and removes them.
An example: WordPress needs two containers, the website and its MySQL or MariaDB database. Without Compose you type 5 Docker commands with about 20 options, and you must remember them for the next time. With Compose, the same settings live in one file that you can keep, copy to another server and share. Below we build that WordPress example both ways and run every command. We tested everything on 14 November 2026 with Docker Compose v5.7.1 and Docker Engine 29.2.1. The outputs are the real ones.
Docker Compose in plain words
| Word | What it means |
|---|---|
| Compose file | The YAML file that describes your app, usually compose.yaml. |
| Service | One part of the app, such as wordpress or db. Compose runs one container for it (or more, if you ask). |
| Project | All the services of one Compose file. By default its name is the folder's name, here wordpress-demo. |
| Network | Compose creates one private network per project, and the services find each other by their service name. |
| Volume | Storage that outlives the container: your database and your uploads stay when a container is recreated. |
Docker's documentation sums it up the same way: Compose is a tool for defining and running multi-container applications, with services, networks and volumes in a single YAML file and one command to start them.
Docker vs Docker Compose: the same app both ways
Docker runs containers one at a time with docker run. Docker Compose does not replace Docker: it reads your file and asks the same Docker Engine to create the containers, the network and the volumes for you.
Here is WordPress with plain Docker commands. You need a network so the two containers can talk, two volumes for the data, and one long docker run per container:
docker network create demo-net
docker volume create demo-db-data && docker volume create demo-wp-data
docker run -d \
--name demo-db \
--network demo-net \
--restart unless-stopped \
-e MARIADB_DATABASE=wordpress \
-e MARIADB_USER=wordpress \
-e MARIADB_PASSWORD=change-me-wordpress \
-e MARIADB_ROOT_PASSWORD=change-me-root \
-v demo-db-data:/var/lib/mysql mariadb:11.8
docker run -d \
--name demo-wordpress \
--network demo-net \
--restart unless-stopped \
-p 8080:80 \
-e WORDPRESS_DB_HOST=demo-db \
-e WORDPRESS_DB_USER=wordpress \
-e WORDPRESS_DB_PASSWORD=change-me-wordpress \
-e WORDPRESS_DB_NAME=wordpress \
-v demo-wp-data:/var/www/html wordpress:7.1It works, but we had to wait by hand: 20 seconds between the two docker run commands so the database was ready, then 8 seconds more. Then WordPress answered with a redirect to its installer:
curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' http://localhost:8080/302 http://localhost:8080/wp-admin/install.phpBut the settings now live only in your shell history. To change one option, you stop, remove and type the whole command again. And nothing makes WordPress wait for the database: you do the waiting.
Here is the same app as a Compose file. Make a folder named wordpress-demo and save this as compose.yaml in it:
services:
db:
image: mariadb:11.8
restart: unless-stopped
environment:
MARIADB_DATABASE: wordpress
MARIADB_USER: wordpress
MARIADB_PASSWORD: ${DB_PASSWORD}
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 5
wordpress:
image: wordpress:7.1
restart: unless-stopped
depends_on:
db:
condition: service_healthy
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
WORDPRESS_DB_NAME: wordpress
volumes:
- wp_data:/var/www/html
volumes:
db_data:
wp_data:Put the passwords in a second file named .env, in the same folder. Compose reads it on its own and fills in ${DB_PASSWORD} and ${DB_ROOT_PASSWORD}. Change these example values:
DB_PASSWORD=change-me-wordpress
DB_ROOT_PASSWORD=change-me-rootWhat each part does:
services: the two containers,dbandwordpress.image: the image and its version,mariadb:11.8andwordpress:7.1.environment: the settings each image reads at start, here the database name, user and passwords.volumes:db_datakeeps the database andwp_datakeeps the WordPress files. Thevolumes:block at the end creates them.healthcheck: a test that tells Docker when MariaDB is really ready, not only started.depends_onwithcondition: service_healthy: WordPress starts only after the database passes its health check (startup order in the documentation).ports:"8080:80"opens port 80 of the container on port 8080 of your computer.WORDPRESS_DB_HOST: db: WordPress reaches the database by its service name. No IP address is needed.
Run it: docker compose up
First, let Compose check the file. --quiet prints nothing when the file is valid:
docker compose config --quiet && echo 'compose.yaml is valid'compose.yaml is validdocker compose config also shows the file as Compose understands it, with the values of .env filled in (variable interpolation). A quick way to check that your variables arrive:
docker compose config | grep -A 5 'WORDPRESS_DB' WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_PASSWORD: change-me-wordpress
WORDPRESS_DB_USER: wordpress
image: wordpress:7.1
networks:
default: null
volumes:
- type: volumeNow start the project. -d runs it in the background and gives you the prompt back:
docker compose up -d Network wordpress-demo_default Creating
Volume wordpress-demo_wp_data Creating
Volume wordpress-demo_db_data Creating
Volume wordpress-demo_wp_data Created
Volume wordpress-demo_db_data Created
Network wordpress-demo_default Created
Container wordpress-demo-db-1 Creating
Container wordpress-demo-db-1 Created
Container wordpress-demo-wordpress-1 Creating
Container wordpress-demo-wordpress-1 Created
Container wordpress-demo-db-1 Starting
Container wordpress-demo-db-1 Started
Container wordpress-demo-db-1 Waiting
Container wordpress-demo-db-1 Healthy
Container wordpress-demo-wordpress-1 Starting
Container wordpress-demo-wordpress-1 StartedCompose created the network and the two volumes, started the database, waited until it was healthy, and only then started WordPress. In a terminal, the same command shows a progress view with the time of each step:

docker compose up -d with Docker Compose v5.7.1. The database needed about 21 seconds to become healthy before WordPress started.Check the state of the project with docker compose ps:
docker compose psNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
wordpress-demo-db-1 mariadb:11.8 "docker-entrypoint.s…" db 24 seconds ago Up 21 seconds (healthy) 3306/tcp
wordpress-demo-wordpress-1 wordpress:7.1 "docker-entrypoint.s…" wordpress 21 seconds ago Up Less than a second 0.0.0.0:8080->80/tcp, [::]:8080->80/tcpGive WordPress a few seconds. Right after up -d, our first curl got no answer at all (000), because Apache inside the container was still starting. A few seconds later:
curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' http://localhost:8080/302 http://localhost:8080/wp-admin/install.phpOpen http://localhost:8080 in a browser (or http://<server-ip>:8080 from another computer) and the WordPress installer appears:

db.How the services find each other
Compose put both containers on a project network named wordpress-demo_default. On it, each service name works as a host name (Networking in Compose). From inside the WordPress container, db resolves to the database container:
docker compose exec wordpress getent hosts db172.26.0.2 dbdocker network ls --filter name=wordpress-demo --format '{{.Name}} {{.Driver}}'wordpress-demo_default bridgeThe IP address can change each time the container is recreated. The name db does not, which is why the Compose file uses names.
The Docker Compose commands you will use
Run them in the folder that holds compose.yaml. Compose finds the project from the folder.
| Command | What it does |
|---|---|
docker compose up -d | Create and start every service, in the background |
docker compose ps | List the containers of the project and their state |
docker compose logs -f | Follow the logs of every service (Ctrl+C to stop) |
docker compose stop | Stop the containers, keep them |
docker compose start | Start the stopped containers again |
docker compose restart wordpress | Restart one service |
docker compose exec db sh | Open a shell in a running service |
docker compose pull | Download newer images |
docker compose config | Check the file and show it with the variables filled in |
docker compose down | Stop and remove containers and the network, keep the volumes |
docker compose down -v | Same, and delete the named volumes (your data) |
The logs of one service, the last 2 lines. Each line starts with the service name:
docker compose logs --tail 2 dbdb-1 | 2026-11-14 14:04:14 0 [Note] mariadbd: ready for connections.
db-1 | Version: '11.8.9-MariaDB-ubu2404' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distributionFor -f, --since and the other options, see our guide to docker logs and docker compose logs.
Restart one service, then stop the whole project and start it again. start waits for the database to be healthy again, like up:
docker compose restart wordpress Container wordpress-demo-wordpress-1 Restarting
Container wordpress-demo-wordpress-1 Starteddocker compose stop
docker compose ps --all --format '{{.Service}} {{.State}}' Container wordpress-demo-wordpress-1 Stopping
Container wordpress-demo-wordpress-1 Stopped
Container wordpress-demo-db-1 Stopping
Container wordpress-demo-db-1 Stopped
db exited
wordpress exiteddocker compose start Container wordpress-demo-db-1 Starting
Container wordpress-demo-db-1 Started
Container wordpress-demo-db-1 Waiting
Container wordpress-demo-db-1 Healthy
Container wordpress-demo-wordpress-1 Starting
Container wordpress-demo-wordpress-1 StartedTo apply a change to compose.yaml, such as a new port or a new image version, run docker compose up -d again: Compose recreates the services that changed. Our docker compose up guide covers that command in detail.
docker compose down: does it delete your data?
No, not by default. down removes the containers and the network, and keeps the named volumes. down -v also deletes the volumes (docker compose down reference). We tested both. First we created a database named notes inside MariaDB:
docker compose exec db sh -c 'mariadb -uroot -p"$MARIADB_ROOT_PASSWORD" -e "CREATE DATABASE notes;"' && echo createdcreatedThen docker compose down:
docker compose down Container wordpress-demo-wordpress-1 Stopping
Container wordpress-demo-wordpress-1 Stopped
Container wordpress-demo-wordpress-1 Removing
Container wordpress-demo-wordpress-1 Removed
Container wordpress-demo-db-1 Stopping
Container wordpress-demo-db-1 Stopped
Container wordpress-demo-db-1 Removing
Container wordpress-demo-db-1 Removed
Network wordpress-demo_default Removing
Network wordpress-demo_default RemovedThe volumes are still there:
docker volume ls --filter name=wordpress-demo --format '{{.Name}}'wordpress-demo_db_data
wordpress-demo_wp_dataAfter a new docker compose up -d, the notes database was still in MariaDB:
docker compose exec db sh -c 'mariadb -uroot -p"$MARIADB_ROOT_PASSWORD" -e "SHOW DATABASES LIKE \"notes\";"'Database (notes)
notesThen docker compose down -v, which deleted both volumes, and with them the database and the WordPress files:
docker compose down -v Container wordpress-demo-wordpress-1 Stopping
Container wordpress-demo-wordpress-1 Stopped
Container wordpress-demo-wordpress-1 Removing
Container wordpress-demo-wordpress-1 Removed
Container wordpress-demo-db-1 Stopping
Container wordpress-demo-db-1 Stopped
Container wordpress-demo-db-1 Removing
Container wordpress-demo-db-1 Removed
Volume wordpress-demo_wp_data Removing
Volume wordpress-demo_db_data Removing
Network wordpress-demo_default Removing
Volume wordpress-demo_wp_data Removed
Volume wordpress-demo_db_data Removed
Network wordpress-demo_default Removeddocker volume ls --filter name=wordpress-demo --format '{{.Name}}' | wc -l0So use docker compose down for everyday stops and updates, and down -v only to delete a test project for good.
Benefits of Docker Compose
- One file describes the whole app. The
compose.yamlabove replaced 5 commands and their 20 options. It is also the documentation of how the app runs. - One command to start or stop everything.
up -danddown, in the right order, every time. - Start order and health checks. WordPress waited 21 seconds for a healthy database instead of failing on its first try.
- A private network with names.
dbreaches the database, whatever its IP address. - Data that survives. Named volumes outlive
downand image updates. - Easy updates.
docker compose pullthendocker compose up -ddownloads new images and recreates only what changed. - Easy to move. Copy the folder (with
compose.yamland.env) to another server and runup -dthere.
Limits of Docker Compose
- One server. A Compose project runs on one Docker host. To spread containers over several servers, look at Kubernetes or Docker Swarm.
- The .env file is plain text. Keep it out of public Git repositories and readable only by you (
chmod 600 .env). - No automatic updates. Compose updates an image only when you run
pullandup -d.
docker-compose or docker compose? compose.yaml or docker-compose.yml?
docker-compose, with a hyphen, is the old Compose V1, a separate Python program that Docker no longer updates. Today Compose is a Docker plugin and you type docker compose, with a space. Check yours:
docker compose versionDocker Compose version v5.7.1For the file name, Docker's documentation prefers compose.yaml, and still reads compose.yml, docker-compose.yaml and docker-compose.yml. If two of them are in the folder, Compose uses compose.yaml.
Many old examples start with a line such as version: "3.8". Compose ignores it today (version is obsolete) and prints a warning. We added that line to a copy of our file:
time="2026-11-14T14:06:05Z" level=warning msg="/tmp/compose-lab-broken/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion"Delete the version: line and the warning goes away. Nothing else changes.
The most common mistake: YAML indentation
YAML uses spaces to show what belongs to what. One space too few is enough to break the file. In a copy of our file, we moved image: of the wordpress service one space to the left:
wordpress:
image: wordpress:7.1
restart: unless-stoppedCompose refused it:
docker compose config --quietyaml: line 20: mapping values are not allowed in this contextThe line number points at the first line Compose could not read, here line 20, restart:, just under the bad line. Use spaces, never tabs, and keep the same number of spaces for keys at the same level. Run docker compose config --quiet after each edit.
Docker Compose on a Synology NAS
On Synology, Container Manager calls a Compose project a Project. You create a project, choose a folder and paste your compose.yaml, and Container Manager runs the same up for you. Our step-by-step guides do exactly this: Immich on Synology and Paperless-ngx on Synology. You can also use the command line over SSH (see how to SSH into a Synology NAS) and put sudo in front of docker compose.
Frequently asked questions
What is Docker Compose in simple words?
A tool that starts an app made of several containers from one file, compose.yaml, with one command: docker compose up -d.
What is the difference between Docker and Docker Compose?
Docker runs containers, one docker run at a time. Docker Compose describes several containers, their network and their volumes in one file, and asks Docker to run them together.
Is Docker Compose free?
Yes. Docker Compose is open source, under the Apache 2.0 license.
Do I need to install Docker Compose separately?
Docker Desktop includes it. On Linux, install Docker's docker-compose-plugin package, as in our guide to install Docker Compose on Ubuntu. docker compose version tells you if it is there.
Does docker compose down delete my data?
No. It removes the containers and the network and keeps the named volumes. Only docker compose down -v deletes the volumes. We tested both above.
Should I name the file compose.yaml or docker-compose.yml?
Both work. compose.yaml is the name Docker recommends today.
Can I use Docker Compose in production?
Yes, on one server. Docker's documentation says Compose works in production, staging, development, testing and CI. For an app spread over several servers, use an orchestrator such as Kubernetes.
Related guides
Leave a comment
Your email address will not be published. Required fields are marked *
