Docker Compose CLI Cheat Sheet
When working with Docker Compose daily, it's easy to forget the exact options or syntax and end up looking things up again. This article organizes the most commonly used Docker Compose commands by what you're trying to do, so you can quickly find what you need.
docker compose
Description
Build
Builds images for your services using the Dockerfile defined in the build section of compose.yml.
docker compose build
Rebuilds images without using the cache. Use this when you've updated dependencies or want a completely fresh build.
docker compose build --no-cache
Pulls images defined in compose.yml from a registry such as Docker Hub. Useful for pre-fetching images for services that don't require a build step.
docker compose pull
Start
Creates and starts containers. Add -d to run them in the background (detached mode). You can specify a service name to start only that service — any services it depends on will also be started automatically.
docker compose up
docker compose up -d
docker compose up -d <service>
Builds images before starting containers. Use this when you want to apply code changes without a separate build step.
docker compose up --build -d
Starts stopped containers. If you stopped them with stop without running docker compose down, use this to resume them.
docker compose start
Restarts containers. Handy when you've updated a config file or a container becomes unresponsive.
docker compose restart
Container Status
Shows the status of each service (running, stopped, etc.). Displays container names, statuses, and exposed ports in a list, making it easy to verify that everything started correctly.
docker compose ps
Displays logs. Use -f to follow logs in real time, and --tail to limit the number of lines shown.
docker compose logs
docker compose logs -f
docker compose logs --tail 100 <service>
Shows the processes running inside service containers. Use this when you want to see exactly what's happening inside a container.
docker compose top
Container Operations
Opens a shell inside a running service container. If the container doesn't have bash (e.g., Alpine Linux-based images), use sh instead.
docker compose exec <service> bash
docker compose exec <service> sh
Runs a command in a one-off container without starting the service. Great for running database migrations or seed scripts. Adding --rm removes the container automatically after it exits.
docker compose run --rm <service> <command>
Copies a file from the host into a container. Useful for pushing in configuration files.
docker compose cp <host-path> <service>:<container-path>
Copies a file from a container to the host. Useful for pulling out log files or configuration files.
docker compose cp <service>:<container-path> <host-path>
Config
Displays the resolved compose.yml with all variables expanded. Useful for verifying that environment variables are being applied correctly.
docker compose config
Lists the names of all services defined in compose.yml. Handy when you need to retrieve service names in a script.
docker compose config --services
Stop / Remove
Stops running containers without removing them. They can be resumed with start or reused the next time you run up.
docker compose stop
Stops and removes containers along with their network.
docker compose down
Also removes volumes. Be careful — any data stored in the volumes will be permanently deleted.
docker compose down -v
Summary
- The basic workflow is: build → start → check status
- Rebuild images whenever you update code or dependencies
- When something goes wrong, check the logs and open a shell inside the container to investigate
- To reset your data, remove everything including volumes