Cloud & DevOps

Docker Commands Cheat Sheet

A Docker commands cheat sheet for images, containers, logs, networks, volumes, Compose, cleanup and troubleshooting.

Docker command-line workflow with container images, instances, networks and volumes
Original concept artwork created for this Circuit Compass guide.

Use this Docker cheat sheet to move from images to running containers and troubleshoot them safely. Names are easier to reuse than container IDs, and cleanup commands deserve a careful preview.

Images and builds

docker build -t app:dev .Build and tag an image from the current context.
docker image lsList local images.
docker pull IMAGEDownload an image.
docker image inspect IMAGEShow detailed image metadata.
docker image rm IMAGERemove an unused image.

Run and manage containers

docker run --name web -p 8080:80 -d IMAGECreate and run a named container in the background.
docker ps -aList running and stopped containers.
docker logs -f webFollow container logs.
docker exec -it web shRun an interactive shell in a running container.
docker stop webRequest a graceful stop.
docker rm webRemove a stopped container.

Compose, networks and volumes

docker compose up -dStart the Compose application.
docker compose logs -fFollow service logs.
docker compose downStop and remove Compose containers and networks.
docker network lsList networks.
docker volume lsList volumes.
docker statsStream resource usage.

Cleanup and safety

docker system df shows Docker disk use. Prune commands remove unused objects and can affect cached builds or stopped environments. List and inspect the exact targets before removing them. Never place secrets in an image layer or commit them in a Compose file.

Frequently asked questions

What is the difference between docker run and docker start?

docker run creates a new container from an image and starts it. docker start restarts an existing stopped container.

How do I see all Docker containers?

Use docker ps -a. Without -a, only running containers are shown.

Sources and further reading

Features, software and prices change. Confirm current details with these sources before making a decision.

Found something that needs updating? Send a correction with the page URL and a supporting source.