When I started playing with Docker, I ran many commands to build images, delete old containers and run new ones. It involved long commands with links, volumes, and other flags.
I searched for a way to automate these tasks and discovered docker-compose.
Note
Note (2025):
This post was originally written in 2016. Docker Compose has evolved significantly since then. The docker-compose command is now integrated as a plugin, and the installation and docker-compose.yml syntax have changed. The post has been updated to reflect modern practices.
Installation
You can install Docker Compose along with Docker Desktop or as a standalone plugin. The recommended approach is to get it with Docker Desktop for your OS1.
Once installed, you can enable Bash completions. Run it as root to make configuration global for all users:
curl -L https://raw.githubusercontent.com/docker/compose/v2/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
Configuration
Next, prepare a docker-compose.yaml file. Here is an example:
services:
web:
build: .
command: php -S 0.0.0.0:8000 -t /code
ports:
- "8000:8000"
volumes:
- .:/code
depends_on:
- db
db:
image: mysql:8.0
environment:
MYSQL_DATABASE: wordpress
MYSQL_ROOT_PASSWORD: your_password
You can find more information about the docker-compose.yaml syntax in the official documentation2.
Usage
Run the environment with:
docker compose up
Or, to run it in the background (detached mode):
docker compose up -d
To stop the services and remove the containers, networks, and volumes, use:
docker compose down -v
Other useful commands include:
docker compose build --force-rm # Rebuild images and clean up
docker compose ps # List containers
I’m still exploring what’s possible with volumes, but I don’t have anything interesting enough to add yet-maybe later.
](https://gagor.pro/generic-cover.webp)