Docker Commands Cheat Sheet

Essential Docker commands for managing containers, images, volumes, networks, and Compose stacks. Bookmark this page for quick reference.

Container Lifecycle

CommandDescription
docker run <image>Create and start a new container from an image
docker run -d -p 8080:80 <image>Run detached with host port 8080 mapped to container port 80
docker run -it <image> /bin/bashRun a container interactively with a shell
docker start <container>Start a stopped container
docker stop <container>Gracefully stop a running container (sends SIGTERM)
docker restart <container>Stop and then start a container
docker rm <container>Remove a stopped container
docker kill <container>Kill a running container immediately (sends SIGKILL)
docker pause <container>Pause all processes in a container
docker unpause <container>Resume all processes in a paused container

Container Inspection

CommandDescription
docker psList running containers
docker ps -aList all containers including stopped ones
docker logs -f <container>Follow (tail) container logs in real time
docker inspect <container>View detailed container configuration as JSON
docker top <container>Show running processes inside a container
docker statsShow live CPU, memory, and I/O usage for all containers
docker port <container>List port mappings for a container
docker diff <container>Show filesystem changes made inside a container
docker exec -it <container> /bin/shOpen an interactive shell in a running container

Image Management

CommandDescription
docker imagesList all locally stored images
docker pull <image>Download an image from a registry
docker push <image>Upload an image to a registry
docker build -t <name> .Build an image from a Dockerfile in the current directory
docker rmi <image>Remove a local image
docker tag <image> <new-tag>Create a new tag for an existing image
docker history <image>Show the layer history of an image
docker save -o <file.tar> <image>Export an image to a tar archive
docker load -i <file.tar>Import an image from a tar archive

Volume Management

CommandDescription
docker volume create <name>Create a new named volume
docker volume lsList all volumes
docker volume inspect <name>View detailed information about a volume
docker volume rm <name>Remove a volume
docker volume pruneRemove all unused volumes

Network Management

CommandDescription
docker network create <name>Create a new network
docker network lsList all networks
docker network inspect <name>View detailed information about a network
docker network connect <net> <container>Connect a running container to a network
docker network disconnect <net> <container>Disconnect a container from a network
docker network rm <name>Remove a network

Docker Compose

CommandDescription
docker compose up -dCreate and start all services in detached mode
docker compose downStop and remove all containers, networks, and volumes
docker compose buildBuild or rebuild all service images
docker compose psList containers managed by Compose
docker compose exec <svc> /bin/shOpen a shell inside a running Compose service
docker compose restart <svc>Restart a specific service
docker compose pullPull the latest images for all services

System & Cleanup

CommandDescription
docker system dfShow Docker disk usage (images, containers, volumes)
docker system pruneRemove all unused containers, networks, and dangling images
docker image pruneRemove dangling (untagged) images
docker container pruneRemove all stopped containers