Docker Compose lets you define and run multi-container applications from a single YAML file, instead of running multiple long docker run commands manually. Modern Docker installations include Compose as an integrated docker compose plugin rather than a separate binary.
Prerequisites
- Docker Engine already installed
- Root or sudo access
Step 1 — Check If Compose Is Already Installed
docker compose version
If this returns a version number, you're already set — it ships with Docker Engine installed via the official repository.
Step 2 — Install the Compose Plugin (If Missing)
sudo apt update
sudo apt install docker-compose-plugin -y
Step 3 — Verify
docker compose version
Step 4 — Create a Test Project
mkdir ~/compose-test && cd ~/compose-test
nano docker-compose.yml
services:
web:
image: nginx:latest
ports:
- "80:80"
restart: unless-stopped
Step 5 — Start the Stack
docker compose up -d
Step 6 — Verify It's Running
docker compose ps
docker ps
Visit http://YOUR_SERVER_IP in a browser — you should see the default Nginx page.
Step 7 — Stop the Stack
docker compose down
Essential Compose Commands
| Command | Purpose |
|---|---|
docker compose up -d | Start services in the background |
docker compose down | Stop and remove containers |
docker compose restart | Restart all services |
docker compose logs -f | Follow logs from all services |
docker compose ps | List running services in this project |
docker compose pull | Download the latest images |
docker compose config | Validate the YAML syntax |
Note on the Legacy docker-compose Binary
You may still see the standalone docker-compose (with a hyphen) command referenced in older tutorials. It's deprecated in favor of the integrated docker compose (no hyphen) plugin used throughout current Docker documentation and this guide.
Common Errors
"docker: 'compose' is not a docker command" — the plugin isn't installed; run Step 2 above.
YAML syntax errors — validate before starting:
docker compose config
Remember YAML requires spaces, never tabs, for indentation.
Best Practices
- Keep one
docker-compose.ymlper project/application - Use
restart: unless-stoppedfor production services - Store secrets in a
.envfile rather than hardcoding them in the YAML
FAQ
What's the difference between docker-compose and docker compose?
They're functionally similar, but docker compose (the plugin, no hyphen) is the current, actively maintained version and is installed alongside Docker Engine by default via the official repository.
Related Articles
- How to Install Docker Engine on Ubuntu & Debian
- Docker Compose .env and Environment Variables
- Docker Compose Troubleshooting: Common Errors & Fixes
