A Docker cheat sheet is a set of notes used for quick reference while using Docker in the real world. I have prepared a Docker cheat sheet that includes an extensive list of Docker commands.
Here, I am presenting my Docker Cheat Sheet (a one-page guide) with all common terms and useful one-liners commands. You can use it as a quick reference guide when working with Docker. If you want to learn more about Docker with detail information and examples, you can read the rest of the article.
If you want to host Docker on Cloud and don’t know how to choose the best Cloud hosting provider. You can read my guide on The 8 Best Docker Hosting Platforms in 2022.
Docker Basic Commands | |
COMMANDS | DESCRIPTIONS |
systemctl start docker | Start Docker service |
systemctl restart docker | Restart Docker service |
systemctl enable docker | Enable Docker to start at reboot |
systemctl status docker | Check Docker service status |
docker –version | Check Docker version |
docker info | Print Docker information in detail |
docker system df | Check disk space being used by your containers |
Docker Container Commands | |
docker ps Or docker container ls | List only running containers |
docker ps -a Or docker container ls -a | List both running and stopped containers |
docker ps -l | List the latest created containers |
docker ps -s | List all containers by their size |
docker ps -qa | List all containers by their ID |
docker stats | Show running container stats |
docker start container-name | Start a container |
docker restart container-name | Restart a container |
docker stop container-name | Stop a container |
docker stop $(docker ps -aq) | Stop all running container |
docker exec -it container-name /bin/bash | SSH into container |
docker logs container-name | Check log of a container |
docker top container-name | Check the running process in a container |
docker inspect -f “{{ .NetworkSettings.IPAddress }}” container-name | Check the IP address of a container |
docker container rename oldname newname | Rename a container |
Docker Run Commands | |
docker container run –name container image | Run a container from an image |
docker container run -d image-name | Run a container in detached mode |
docker container run -it image-name /bin/bash | Run a container in interactive mode |
docker container run -d -p [host-port]:[container-port] image-name | Run a container and publish a container port |
docker container run –rm image-name | Run a container that automatically removes a container when it exits |
Copy a File Between Container and Host | |
docker cp container-name:/file/path /host/path | Copy a file from container to host |
docker cp /host/file/path container-name:/path/ | Copy a file from host to container |
Docker Image Commands | |
docker images | List all Docker images |
docker tag oldname:tag newname:tag | Rename an image |
docker search image-name | Search available images on the Docker Hub |
docker history image-name | Check command history of any image |
docker build -t image-name Dockerfile | Build an Image from Dockerfile |
Docker Registry and Repository | |
docker login | Login to Docker registry |
docker logout | Logout from a Docker registry |
docker search image-name | Search an image from the Docker registry |
docker pull myimage:tag | Pull an image from a registry |
docker push myrepo/myimage | Push an image to registry |
Import and Export Container and Image | |
docker save -o image.tar image-name | Export an image to a TAR archive |
docker load < image.tar | Import an image from a TAR archive |
docker commit container-name image-name | Create an image from a container |
docker export container-name > container.tar | Export a container to a TAR archive |
docker import container-name < container.tar | Import a container from TAR archive |
Remove Container, Image, Network and Volume | |
docker container rm container-name | Remove a stopped container |
docker container prune -f | Remove all stopped container |
docker rmi image-name | Remove an unused Docker image |
docker rmi $(docker images -a -q) | Remove all unused Docker images |
docker image prune -a | Remove all dangling images |
docker system prune -af | Remove unused and dangling images, networks, containers, and volumes |
docker volume rm volume-name | Remove a Docker volume |
docker network rm network-name | Remove a Docker network |
Conclusion
In the above Docker Cheat Sheet, you learned all docker commands with a brief description. You can now use this Docker Cheat Sheet as a quick reference guide when working with Docker.
To learn more about Docker check out my all published docker-tutorial.
Recommended Reading
- How to Stop / Remove all Docker Containers and Images
- How to Install and Use Docker Compose on Ubuntu 20.04 | 22.04
- How to Install and Use Docker on Ubuntu 20.04 | 22.04
- Docker Exec – How to Connect to a Docker Container
- How To Remove Docker Images, Containers & Volumes
- How to Use Docker Push & Pull Command with Examples
- How To List / Start / Stop Docker Containers
- How to Use Docker Run Command with Examples