Docker Cheatsheet
Common Docker commands for building, running, and managing containers and images.
Docker simplifies application deployment by packaging code and dependencies into lightweight containers. This cheatsheet covers image management, container lifecycle, Docker Compose for multi-service apps, and system maintenance.
All commands target the Docker CLI. For container orchestration at scale, see the Kubernetes cheatsheet.
Image Management
docker pull <image>docker imagesdocker build -t <name> .docker build --no-cache -t <name> .docker tag <image> <repo>/<name>:<tag>docker push <repo>/<name>:<tag>docker rmi <image>Container Lifecycle
docker run <image>docker run -d --name <name> <image>docker run --rm <image>docker run -v <host>:<container> <image>docker run --env <KEY>=<val> <image>docker psdocker ps -adocker start <container>docker stop <container>docker restart <container>docker rm <container>docker rm -f <container>Debugging & Shell
docker logs <container>docker logs --tail 100 -f <container>docker exec -it <container> <cmd>docker cp <src> <container>:<dest>docker cp <container>:<src> <dest>docker inspect <container>docker statsDocker Compose
docker-compose updocker-compose downdocker-compose logs -fdocker-compose builddocker-compose exec <service> <cmd>System & Cleanup
docker system dfdocker system prunedocker system prune -a --volumesdocker volume lsdocker network lsDocker Cheatsheet
Common Docker commands for building, running, and managing containers and images.
Docker simplifies application deployment by packaging code and dependencies into lightweight containers. This cheatsheet covers image management, container lifecycle, Docker Compose for multi-service apps, and system maintenance.
All commands target the Docker CLI. For container orchestration at scale, see the Kubernetes cheatsheet.
Image Management
docker pull <image> — Pull an image from a registry (Docker Hub, GHCR, etc.).docker images — List all locally available images.docker build -t <name> . — Build an image from a Dockerfile in the current directory.docker build --no-cache -t <name> . — Force a fresh build without using the layer cache.docker tag <image> <repo>/<name>:<tag> — Tag an image with a new name for pushing.docker push <repo>/<name>:<tag> — Push an image to a remote registry.docker rmi <image> — Remove one or more images by name or ID.Container Lifecycle
docker run <image> — Create and start a container from an image.docker run -d --name <name> <image> — Run a container in detached (background) mode with a name.docker run --rm <image> — Run a container and automatically remove it when it exits.docker run -v <host>:<container> <image> — Mount a host directory as a volume inside the container.docker run --env <KEY>=<val> <image> — Set environment variables in the container.docker ps — List currently running containers.docker ps -a — List all containers, including stopped ones.docker start <container> — Start a stopped container.docker stop <container> — Gracefully stop a running container (SIGTERM).docker restart <container> — Restart a running container.docker rm <container> — Remove a stopped container.docker rm -f <container> — Force remove a running container (SIGKILL).Debugging & Shell
docker logs <container> — View logs from a container.docker logs --tail 100 -f <container> — Tail the last 100 log lines and follow new output.docker exec -it <container> <cmd> — Run a command in a running container interactively.docker cp <src> <container>:<dest> — Copy a file or directory from host to container.docker cp <container>:<src> <dest> — Copy a file or directory from container to host.docker inspect <container> — Display low-level JSON metadata about a container or image.docker stats — Show live CPU, memory, and network usage for running containers.Docker Compose
docker-compose up — Create and start all services defined in docker-compose.yml.docker-compose down — Stop and remove all containers, networks, and volumes defined in compose.docker-compose logs -f — Follow logs from all services in the compose project.docker-compose build — Build or rebuild all images defined in docker-compose.yml.docker-compose exec <service> <cmd> — Run a command in a running compose service.System & Cleanup
docker system df — Show disk usage by images, containers, volumes, and build cache.docker system prune — Remove all unused containers, networks, and dangling images.docker system prune -a --volumes — Aggressive cleanup — removes all unused images, containers, volumes, and build cache.docker volume ls — List all Docker volumes.docker network ls — List all Docker networks.