Docker Compose Cheat Sheet: The 10 Commands You Actually Need
Most Docker Compose tutorials give you 50 commands. You'll use 10 of them 95% of the time.
Here are those 10, what they do, and when to use each.
The Setup
All these commands assume you have a docker-compose.yml file in your current directory. Run them from the same folder as that file.
1. Start Everything
docker compose up -d
What it does: Starts all containers defined in your compose file. The -d flag runs them in the background (detached mode) so you get your terminal back.
When to use: First time starting a service, or after stopping it.
Without -d: Runs in the foreground — you see all logs but lose your terminal. Useful for debugging.
2. Stop Everything (Keep Data)
docker compose down
What it does: Stops and removes containers, but keeps your volumes (data) intact.
When to use: Restarting services, applying config changes, temporary shutdown.
Important: Your data is safe. Volumes persist unless you explicitly delete them.
3. Stop Everything AND Delete Data
docker compose down -v
What it does: Stops containers AND deletes all volumes (your data).
When to use: Starting completely fresh. Resetting a broken database. Uninstalling a service.
Warning: This is destructive. Your database, files, and configs stored in volumes are gone.
4. View Running Containers
docker compose ps
What it does: Shows all containers for this compose project — their state, ports, and names.
When to use: Checking if everything started correctly. Seeing what's running.
Sample output:
NAME STATUS PORTS
nextcloud-app Up 2 hours 0.0.0.0:8080->80/tcp
nextcloud-db Up 2 hours
5. View Logs
docker compose logs -f
What it does: Shows logs from all containers. -f follows in real-time (like tail -f).
When to use: Debugging why something isn't working. Watching startup.
Single service logs:
docker compose logs -f nextcloud
Last 100 lines only:
docker compose logs --tail=100
6. Restart a Single Service
docker compose restart nextcloud
What it does: Restarts one specific container without touching others.
When to use: A service got stuck. Applied a config change. Memory leak causing slowdown.
Restart everything:
docker compose restart
7. Pull Latest Images
docker compose pull
What it does: Downloads the latest version of all images in your compose file.
When to use: Before updating. Part of your monthly maintenance routine.
Then apply the updates:
docker compose pull && docker compose up -d
This is your standard update workflow for every self-hosted service.
8. Execute a Command Inside a Container
docker compose exec nextcloud bash
What it does: Opens a terminal session inside the running container.
When to use: Debugging. Running maintenance commands. Checking config files.
Single command instead of shell:
docker compose exec nextcloud php occ status
Exit the container:
exit
9. Check Resource Usage
docker stats
What it does: Shows live CPU, memory, network, and disk usage for all running containers.
When to use: Server running slow — find which container is the culprit. Memory planning.
Not compose-specific — shows all Docker containers system-wide.
10. Remove Stopped Containers and Unused Images
docker system prune
What it does: Cleans up stopped containers, unused networks, and dangling images. Frees disk space.
When to use: Monthly maintenance. Disk getting full. After lots of updates.
Nuclear option (also removes unused volumes):
docker system prune -a --volumes
Only use this if you know what you're doing — it can delete data.
The Workflow You'll Actually Use
Starting a new service:
# 1. Create docker-compose.yml
# 2. Start it
docker compose up -d
# 3. Check it started
docker compose ps
# 4. Check logs if something's wrong
docker compose logs -f
Monthly maintenance:
docker compose pull
docker compose up -d
docker system prune
Debugging a broken service:
docker compose logs -f servicename
docker compose restart servicename
# If still broken:
docker compose exec servicename bash
Starting fresh:
docker compose down -v
docker compose up -d
Quick Reference Card
| Command | What it does |
|---|---|
docker compose up -d |
Start all services |
docker compose down |
Stop all (keep data) |
docker compose down -v |
Stop all + delete data |
docker compose ps |
List running containers |
docker compose logs -f |
Watch all logs |
docker compose logs -f [name] |
Watch one service's logs |
docker compose restart [name] |
Restart one service |
docker compose pull |
Update images |
docker compose exec [name] bash |
Shell into container |
docker stats |
Live resource usage |
docker system prune |
Clean up unused stuff |
The One Thing Most Beginners Get Wrong
Running docker compose down -v when they meant docker compose down.
The -v flag deletes your volumes — your actual data. Databases, files, configs. Gone.
If you're not sure which to use: docker compose down (no -v) is almost always what you want. It just stops the containers. Your data stays.
Want the Full Setup Guide?
This cheat sheet covers day-to-day commands. If you want the full guide — Ubuntu Server install, Docker setup from scratch, and configs for 10 self-hosted apps (Pi-hole, WireGuard, Vaultwarden, Nextcloud, Jellyfin, and more) — it's all here:
Homelab Starter Guide → ($12)
Prim Ghost builds practical guides for self-hosters and homelab beginners.
Top comments (0)