My Docker Cheat Sheet
Disclaimer
This content is part of / inspired by one of our online courses/training. We are offering up to 80% OFF on these materials, during the Black Friday 2019.
You can receive your discount here.
I’ve been using Docker for years now, in my previous professional experiences and for my company (eralabs.io) customers and I wanted to share my knowledge, that’s why I started Painless Docker Course.
I write a lot about Docker, containers, orchestration and distributed systems and I found it exciting that many of the book readers were satisfied.
This cheat sheet is a part of the original one that you can find in Painless Docker Course.
The git repo is public and your contributions are welcome.
Update: I created a dedicated website for this cheat sheet, you can see it here: https://dockercheatsheet.painlessdocker.com/
Installation
Linux
curl -sSL https://get.docker.com/ | shMac
Use this link to download the dmg.
https://download.docker.com/mac/stable/Docker.dmgWindows
Use the msi installer:
https://download.docker.com/win/stable/InstallDocker.msiDocker Registries & Repositories
Login to a Registry
docker logindocker login localhost:8080
Logout from a Registry
docker logoutdocker logout localhost:8080
Searching an Image
docker search nginxdocker search nginx --stars=3 --no-trunc busybox
Pulling an Image
docker pull nginxdocker pull eon01/nginx localhost:5000/myadmin/nginx
Pushing an Image
docker push eon01/nginxdocker push eon01/nginx localhost:5000/myadmin/nginx
Running Containers
Creating a Container
docker create -t -i eon01/infinite --name infiniteRunning a Container
docker run -it --name infinite -d eon01/infiniteRenaming a Container
docker rename infinite infinityRemoving a Container
docker rm infiniteUpdating a Container
docker update --cpu-shares 512 -m 300M infiniteStarting & Stopping Containers
Starting
docker start nginxStopping
docker stop nginxRestarting
docker restart nginxPausing
docker pause nginxUnpausing
docker unpause nginxBlocking a Container
docker wait nginxSending a SIGKILL
docker kill nginxConnecting to an Existing Container
docker attach nginxGetting Information about Containers
Running Containers
docker psdocker ps -a
Container Logs
docker logs infiniteInspecting Containers
docker inspect infinitedocker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)
Containers Events
docker events infinitePublic Ports
docker port infiniteRunning Processes
docker top infiniteContainer Resource Usage
docker stats infiniteInspecting Changes to Files or Directories on a Container’s Filesystem
docker diff infiniteManipulating Images
Listing Images
docker imagesBuilding Images
docker build .docker build github.com/creack/docker-firefoxdocker build - < Dockerfiledocker build - < context.tar.gzdocker build -t eon/infinite .docker build -f myOtherDockerfile .curl example.com/remote/Dockerfile | docker build -f - .
Removing an Image
docker rmi nginxLoading a Tarred Repository from a File or the Standard Input Stream
docker load < ubuntu.tar.gzdocker load --input ubuntu.tar
Save an Image to a Tar Archive
docker save busybox > ubuntu.tarShowing the History of an Image
docker historyCreating an Image Fron a Container
docker commit nginxTagging an Image
docker tag nginx eon01/nginxPushing an Image
docker push eon01/nginxNetworking
Creating Networks
docker network create -d overlay MyOverlayNetworkdocker network create -d bridge MyBridgeNetworkdocker network create -d overlay \
--subnet=192.168.0.0/16 \
--subnet=192.170.0.0/16 \
--gateway=192.168.0.100 \
--gateway=192.170.0.100 \
--ip-range=192.168.1.0/24 \
--aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \
--aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \
MyOverlayNetwork
Removing a Network
docker network rm MyOverlayNetworkListing Networks
docker network lsGetting Information About a Network
docker network inspect MyOverlayNetworkConnecting a Running Container to a Network
docker network connect MyOverlayNetwork nginxConnecting a Container to a Network When it Starts
docker run -it -d --network=MyOverlayNetwork nginxDisconnecting a Container from a Network
docker network disconnect MyOverlayNetwork nginxCleaning Docker
Removing a Running Container
docker rm nginxRemoving a Container and its Volume
docker rm -v nginxRemoving all Exited Containers
docker rm $(docker ps -a -f status=exited -q)Removing All Stopped Containers
docker rm `docker ps -a -q`Removing a Docker Image
docker rmi nginxRemoving Dangling Images
docker rmi $(docker images -f dangling=true -q)Removing all Images
docker rmi $(docker images -a -q)Stopping & Removing all Containers
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)Removing Dangling Volumes
docker volume rm $(docker volume ls -f dangling=true -q)Docker Swarm
Installing Docker Swarm
curl -ssl https://get.docker.com | bashInitializing the Swarm
docker swarm init --advertise-addr 192.168.10.1Getting a Worker to Join the Swarm
docker swarm join-token workerGetting a Manager to Join the Swarm
docker swarm join-token managerListing Services
docker service lsListing nodes
docker node lsCreating a Service
docker service create --name vote -p 8080:80 instavote/voteListing Swarm Tasks
docker service psScaling a Service
docker service scale vote=3Updating a Service
docker service update --image instavote/vote:movies votedocker service update --force --update-parallelism 1 --update-delay 30s nginxdocker service update --update-parallelism 5--update-delay 2s --image instavote/vote:indent votedocker service update --limit-cpu 2 nginxdocker service update --replicas=5 nginx
Connect Deeper
If you resonated with this article, you can find more interesting content in Painless Docker Course.
At Eralabs, will be happy to help you with your Docker and Cloud projects, contact us and let’s talk about your projects.
Subscribe to DevOpsLinks : An Online Community Of Thousands Of IT Experts & DevOps Enthusiast From All Over The World.
You may be also interested in joining our newsletter Shipped, a newsletter focused on containers, orchestration and serverless technologies.
You can find me on Twitter, Clarity or my website and you can also check my books: SaltStack For DevOps.
Don’t forget to join my last project Jobs For DevOps!
If you liked this post, please recommend it and share it with your followers.

