Guides

Docker commands cheat sheet: containers, images, Compose and cleanup

docker ps, rm, rmi, compose up -d and system prune — the Docker commands used daily, grouped by containers, images, Compose and freeing up disk space.

Published ~9 min read

Short answer: docker ps lists running containers, docker compose up -d starts everything in a compose.yaml in the background, and docker system prune clears out stopped containers and unused images. The full reference below covers containers, images, compose and cleanup — the commands you reach for daily, grouped by what they do.

Containers: run, stop, remove

CommandWhat it does
docker psList running containers
docker ps -aList every container, running or stopped
docker run -d --name app nginxStart a new container in the background
docker start appStart a stopped container by name
docker stop appStop a running container (gives it time to shut down)
docker restart appStop then start a container
docker rm appRemove a stopped container
docker rm -f appStop and remove a container in one step
docker stop $(docker ps -q)Stop every running container
docker logs -f appFollow a container's logs live
docker exec -it app bashOpen a shell inside a running container
docker inspect appFull JSON configuration of a container
docker statsLive CPU, memory and network usage per container

docker stop sends SIGTERM and waits 10 seconds before forcing a SIGKILL; docker kill sends SIGKILL immediately, for a container that ignores the polite request. A name in these examples (app) can always be a container ID instead — docker ps shows both.

Images: pull, build, remove

CommandWhat it does
docker imagesList images stored locally
docker pull nginx:1.27Download an image without running it
docker build -t myapp .Build an image from a Dockerfile in the current directory
docker rmi myappRemove an image by name or ID
docker rmi $(docker images -q)Remove every image not in use by a container
docker tag myapp:latest myapp:v2Give an existing image a second name
docker image inspect myappFull configuration and layer history of an image

Docker Compose

CommandWhat it does
docker compose up -dCreate and start every service in the background
docker compose up -d --buildSame, rebuilding images first
docker compose psList this project's containers
docker compose logs -fFollow every service's logs together
docker compose logs -f appFollow one service's logs
docker compose restart appRestart one service
docker compose stopStop every service without removing containers
docker compose downStop and remove containers, networks (keeps named volumes)
docker compose down -vSame, and also remove named volumes — deletes their data
docker compose exec app bashOpen a shell inside a running service
docker compose configPrint the fully resolved configuration, with .env values filled in

Cleaning up disk space

CommandWhat it removes
docker container pruneEvery stopped container
docker image pruneDangling images only (untagged layers nothing points to)
docker image prune -aEvery image not used by a running container
docker volume pruneEvery volume not used by any container
docker system pruneStopped containers, dangling images, unused networks and build cache
docker system prune -a --volumesAll of the above, plus every unused image and volume
docker system dfHow much disk Docker is using, broken down by category

Networks and volumes

Networks
docker network ls                        # list networks
docker network create mynet              # create one
docker network inspect mynet             # which containers are attached, and their IPs
docker run --network mynet --name app nginx
Volumes
docker volume ls
docker volume create mydata
docker run -v mydata:/var/lib/data --name app nginx   # named volume
docker run -v /srv/app/data:/var/lib/data --name app nginx  # bind mount to a host path

Finding what is using your disk

Breakdown by category
docker system df -v     # -v: per-image and per-container detail, not just totals

None of these commands need Docker Desktop — on a VPS you run the Engine directly; installing Docker on Ubuntu and Debian covers the setup, including adding your user to the docker group so you do not need sudo in front of every command above.

For a worked example that uses a good chunk of this reference together — pull, compose up, logs, volumes — see self-hosting n8n with Docker Compose.

Frequently asked

How do I stop every running Docker container at once?

docker stop $(docker ps -q) stops all of them. Add -a to docker ps if you also want to catch containers already stopped, though stopping one that is already stopped does nothing.

What is the difference between docker rmi and docker rm?

docker rm removes a container; docker rmi removes an image. A container is a running or stopped instance; an image is the template it was created from. docker rmi fails if any container, even a stopped one, still references the image.

What does docker system prune actually delete?

Stopped containers, dangling images (untagged layers nothing points to), unused networks and the build cache. It does not touch images still backing a container or named volumes — add -a for every unused image too, and --volumes for unused volumes as well.

What replaced docker-compose (with the hyphen)?

Compose V2, built into current Docker Engine as the docker compose subcommand (with a space). The standalone Python-based docker-compose (Compose V1) reached end of life in mid-2023.

Related articles

All guides