Docker Comprehensive Cheat Sheet
1. Docker Basics
Command Description
docker --version Show Docker version
docker info Display system-wide information
docker help Show help for Docker commands
2. Working with Images
Command Description
docker pull <image> Download image from Docker Hub
docker images List all local images
docker rmi <image> Remove an image
docker build -t <name>:<tag> <path> Build an image from a Dockerfile
docker tag <image> <repo>/<image>:<tag> Tag an image
docker push <repo>/<image>:<tag> Push image to registry
docker save -o <file>.tar <image> Save image to a tar archive
docker load -i <file>.tar Load image from a tar archive
3. Container Management
Command Description
docker run <image> Run a container from image
docker run -d <image> Run in detached mode
docker run -it <image> /bin/bash Run interactively with a shell
docker run --name <name> <image> Assign a name to the container
docker ps List running containers
docker ps -a List all containers
docker stop <container> Stop a running container
docker start <container> Start a stopped container
docker restart <container> Restart a container
docker rm <container> Remove a container
docker exec -it <container> /bin/bash Run a command in a running container
docker logs <container> View logs of a container
docker inspect <container|image> View detailed information
docker top <container> Show running processes in container
4. Networking
Command Description
docker network ls List all networks
docker network create <network> Create a new network
docker network rm <network> Remove a network
docker network inspect <network> View network details
docker run --network <network> <image> Connect container to a network
5. Volumes & Data
Command Description
docker volume ls List all volumes
docker volume create <volume> Create a new volume
docker volume rm <volume> Remove a volume
docker run -v <host_path>:<container_path> Mount host directory as a volume
<image>
docker run -v <volume>:<container_path> Mount Docker volume
<image>
docker volume inspect <volume> View volume details
6. Cleaning Up
Command Description
docker system prune Remove unused data
docker rm $(docker ps -aq) Remove all containers
docker rmi $(docker images -q) Remove all images
docker volume prune Remove all unused volumes
docker network prune Remove all unused networks
7. Docker Compose
Command Description
docker compose up Start services defined in docker-compose.yml
docker compose up -d Start in detached mode
docker compose down Stop and remove containers, networks, etc.
docker compose ps List containers
docker compose logs View logs
docker compose build Build or rebuild services
8. Dockerfile Essentials
Instruction Description
FROM Base image
RUN Execute command during build
CMD Default command to run
ENTRYPOINT Set container entrypoint
COPY Copy files/directories
ADD Copy files/directories (with extra features)
WORKDIR Set working directory
ENV Set environment variable
EXPOSE Expose port
VOLUME Create mount point for volumes
9. Docker Swarm (Orchestration)
Command Description
docker swarm init Initialize a swarm
docker swarm join ... Join a node to a swarm
docker service create ... Create a new service
docker service ls List services
docker service ps <service> List tasks of a service
docker stack deploy -c <file> <name> Deploy a stack
docker node ls List swarm nodes
docker stack rm <name> Remove a stack
10. Miscellaneous
Command Description
docker stats Show container resource usage
docker history <image> Show image history
docker export <container> > file.tar Export container filesystem
docker import <file.tar> Import from a tarball
docker login Log in to Docker Hub
docker logout Log out from Docker Hub
11. Useful Shortcuts
Stop all running containers:
docker stop $(docker ps -q)
Remove all stopped containers:
docker rm $(docker ps -a -q)
Remove all images:
docker rmi $(docker images -q)
Remove dangling volumes:
docker volume rm $(docker volume ls -qf dangling=true)
12. References & Further Reading
Official Docker CLI Cheat Sheet (PDF)[1]
The Ultimate Docker Cheat Sheet (dockerlabs)[2]
Docker Commands Cheat Sheet (Spacelift)[3]
Complete Guide (GeeksforGeeks)[4]
Quick Reference (quickref.me)[5]
Hostinger Docker Cheat Sheet[6]
This cheat sheet covers the most essential Docker commands and concepts for daily
development, deployment, and troubleshooting. For more advanced usage and updates,
refer to the official Docker documentation or downloadable cheat sheets from trusted
sources.
1. https://docs.docker.com/get-started/docker_cheatsheet.pdf
2. https://dockerlabs.collabnix.com/docker/cheatsheet/
3. https://spacelift.io/blog/docker-commands-cheat-sheet
4. https://www.geeksforgeeks.org/devops/docker-cheat-sheet/
5. https://quickref.me/docker.html
6. https://www.hostinger.com/in/tutorials/docker-cheat-sheet