Docker Commands Cheat Sheet
Essential Docker commands for managing containers, images, volumes, networks, and Compose stacks. Bookmark this page for quick reference.
| Command | Description |
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/bash | Run 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 |
| Command | Description |
docker ps | List running containers |
docker ps -a | List 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 stats | Show 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/sh | Open an interactive shell in a running container |
| Command | Description |
docker images | List 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 |
| Command | Description |
docker volume create <name> | Create a new named volume |
docker volume ls | List all volumes |
docker volume inspect <name> | View detailed information about a volume |
docker volume rm <name> | Remove a volume |
docker volume prune | Remove all unused volumes |
| Command | Description |
docker network create <name> | Create a new network |
docker network ls | List 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 |
| Command | Description |
docker compose up -d | Create and start all services in detached mode |
docker compose down | Stop and remove all containers, networks, and volumes |
docker compose build | Build or rebuild all service images |
docker compose ps | List containers managed by Compose |
docker compose exec <svc> /bin/sh | Open a shell inside a running Compose service |
docker compose restart <svc> | Restart a specific service |
docker compose pull | Pull the latest images for all services |
| Command | Description |
docker system df | Show Docker disk usage (images, containers, volumes) |
docker system prune | Remove all unused containers, networks, and dangling images |
docker image prune | Remove dangling (untagged) images |
docker container prune | Remove all stopped containers |