Docker: Docker Cheat Sheet

Share At:

Getting Started Repo for Snowplow Kafka with Docker – Full-Stack Feed

Docker cheat sheet is a set of notes used for quick reference while using Docker in the real world. Below is the Docker cheat sheet that includes an extensive list of Docker commands. You can use it as a quick reference guide when working with Docker. 

Docker Basic Commands

COMMANDSDESCRIPTIONS
systemctl start dockerStart Docker service
systemctl restart dockerRestart Docker service
systemctl enable dockerEnable Docker to start at reboot
systemctl status dockerCheck Docker service status
docker –versionCheck Docker version
docker infoPrint Docker information in detail
docker system dfCheck disk space being used by your containers

Docker Container Commands

docker ps Or docker container lsList only running containers
docker ps -a Or docker container ls -aList both running and stopped containers
docker ps -lList the latest created containers
docker ps -sList all containers by their size
docker ps -qaList all containers by their ID
docker statsShow running container stats
docker start container-nameStart a container
docker restart container-nameRestart a container
docker stop container-nameStop a container
docker stop $(docker ps -aq)Stop all running container
docker exec -it container-name /bin/bashSSH into container
docker logs container-nameCheck log of a container
docker top container-nameCheck the running process in a container
docker inspect -f “{{ .NetworkSettings.IPAddress }}” container-nameCheck the IP address of a container
docker container rename oldname newnameRename a container

Docker Run Commands

docker container run –name container imageRun a container from an image
docker container run -d image-nameRun a container in detached mode
docker container run -it image-name /bin/bashRun a container in interactive mode
docker container run -d -p [host-port]:[container-port] image-nameRun a container and publish a container port
docker container run –rm image-nameRun a container that automatically removes a container when it exits

Copy a File Between Container and Host

docker cp container-name:/file/path /host/pathCopy 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 imagesList all Docker images
docker tag oldname:tag newname:tagRename an image
docker search image-nameSearch available images on the Docker Hub
docker history image-nameCheck command history of any image
docker build -t image-name DockerfileBuild an Image from Dockerfile

Docker Registry and Repository

docker loginLogin to Docker registry
docker logoutLogout from a Docker registry
docker search image-nameSearch an image from the Docker registry
docker pull myimage:tagPull an image from a registry
docker push myrepo/myimagePush an image to registry

Import and Export Container and Image

docker save -o image.tar image-nameExport an image to a TAR archive
docker load < image.tarImport an image from a TAR archive
docker commit container-name image-nameCreate an image from a container
docker export container-name > container.tarExport a container to a TAR archive
docker import container-name < container.tarImport a container from TAR archive

Remove Container, Image, Network and Volume

docker container rm container-nameRemove a stopped container
docker container prune -fRemove all stopped container
docker rmi image-nameRemove an unused Docker image
docker rmi $(docker images -a -q)Remove all unused Docker images
docker image prune -aRemove all dangling images
docker system prune -afRemove unused and dangling images, networks, containers, and volumes
docker volume rm volume-nameRemove a Docker volume
docker network rm network-nameRemove 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.

Happy Learning !!!


Share At:
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Back To Top

Contact Us