Docker Compose is a tool for defining and running multi-container Docker applications. When using Docker, running and managing multiple containers becomes cumbersome. Docker Compose solves this problem.
You use YAML to configure your application services. The file is conventionally named docker-compose.yml (or compose.yaml), but you can give it a different name and point to it explicitly. Compose provides the docker compose command to manage the containers defined in that file.
Also check
- How to Install and Use Docker in Ubuntu 20.04
- How to install and configure docker In Centos 8
- Running Postgresql 14 with Docker and Docker-Compose
- Docker as a build agent – Run Jenkins builds on Docker
Installing Docker Compose
You can run Compose on macOS, Windows, and 64-bit Linux.
Docker Compose relies on Docker Engine, so make sure you have Docker Engine installed before proceeding.
Modern Docker Compose (v2) ships as a plugin for the Docker CLI and is invoked as docker compose (two words). If you installed Docker Engine or Docker Desktop recently, it is already included. On Debian/Ubuntu you can install or update it explicitly from Docker’s repository:
sudo apt-get update
sudo apt-get install docker-compose-plugin
On RPM-based distributions (CentOS, Fedora, RHEL):
sudo yum install docker-compose-plugin
Verify the installation:
docker compose version
Older guides install Compose with
pip install docker-compose. That is Compose v1 (the Pythondocker-composecommand), which reached end of life in 2024 and was removed from Docker’s official images in 2025. Use thedocker composev2 plugin shown above instead — the sub-commands are the same, you just replace the hyphen indocker-composewith a space (docker compose).
WordPress MySQL example
You can use Docker Compose to easily run WordPress in an isolated environment built with Docker containers. This quick-start demonstrates how to use Compose to set up and run WordPress.
Sample docker-compose.yaml file:
services:
db:
image: mysql:8.4
volumes:
- ~/apps/wordpress/db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: toor
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ~/apps/wordpress/site:/var/www/html
ports:
- 8000:80
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
The top-level
versionkey (for exampleversion: "3.9") that older Compose files start with is obsolete in Compose v2 — it is ignored and only prints a warning, so it has been dropped here.mysql:8.4is the current MySQL LTS release (MySQL 8.0 reached end of life in April 2026), andwordpress:latestalways pulls the newest release — pin a specific tag such aswordpress:6.8if you need reproducible builds.
Running the project:
docker compose up -d
Open a shell in the running WordPress container:
docker compose exec wordpress sh
Use http://localhost as the IP address, and open http://localhost:8000 in a web browser.
If you need elevated privileges to bring up the containers, you can set privileged and user on a service:
services:
db:
image: mysql:8.4
volumes:
- ~/apps/wordpress/db:/var/lib/mysql
privileged: true
user: root
environment:
MYSQL_ROOT_PASSWORD: toor
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
Shutdown and cleanup
The command docker compose down removes the containers and default network, but preserves your WordPress database (the named volume).
To also remove the database volume, add the --volumes flag:
docker compose down --volumes