Docker Cheat Sheet

I love Docker, containers, orchestration and distributed systems and here is my cheat sheet:



curl -sSL | sh


Use this link to download the dmg.


Use the msi installer:

Login to a Registry

docker login
docker login localhost:8080

Logout from a Registry.

docker logout
docker logout localhost:8080

Searching an Image

docker search nginx
docker search nginx --stars=3 --no-trunc busybox

Pulling an Image

docker pull nginx
docker pull eon01/nginx localhost:5000/myadmin/nginx

Pushing an Image

docker push eon01/nginx
docker push eon01/nginx localhost:5000/myadmin/nginx

Running Containers

Creating a Container

docker create -t -i eon01/infinite --name infinite

Running a Container

docker run -it --name infinite -d eon01/infinite

Renaming a Container

docker rename infinite infinity

Removing a Container

docker rm infinite

Updating a Container

docker update --cpu-shares 512 -m 300M infinite


docker start nginx


docker stop nginx


docker restart nginx


docker pause nginx


docker unpause nginx

Blocking a Container

docker wait nginx

Sending a SIGKILL

docker kill nginx

Connecting to an Existing Container

docker attach nginx

Running Containers

docker ps
docker ps -a

Container Logs

docker logs infinite

Inspecting Containers

docker inspect infinite
docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)

Containers Events

docker events infinite

Public Ports

docker port infinite

Running Processes

docker top infinite

Container Resource Usage

docker stats infinite

Inspecting changes to files or directories on a container’s filesystem

docker diff infinite

Listing Images

docker images

Building Images

docker build .
docker build
docker build - < Dockerfile
docker build - < context.tar.gz
docker build -t eon/infinite .
docker build -f myOtherDockerfile .
curl | docker build -f - .

Removing an Image

docker rmi nginx

Loading a Tarred Repository from a File or the Standard Input Stream

docker load < ubuntu.tar.gz
docker load --input ubuntu.tar

Save an Image to a Tar Archive

docker save busybox > ubuntu.tar

Showing the History of an Image

docker history

Creating an Image From a Container

docker commit nginx

Tagging an Image

docker tag nginx eon01/nginx

Pushing an Image

docker push eon01/nginx

Creating Networks

docker network create -d overlay MyOverlayNetwork
docker network create -d bridge MyBridgeNetwork
docker network create -d overlay \
  --subnet= \
  --subnet= \
  --gateway= \
  --gateway= \
  --ip-range= \
  --aux-address="my-router=" --aux-address="my-switch=" \
  --aux-address="my-printer=" --aux-address="my-nas=" \

Removing a Network

docker network rm MyOverlayNetwork

Listing Networks

docker network ls

Getting Information About a Network

docker network inspect MyOverlayNetwork

Connecting a Running Container to a Network

docker network connect MyOverlayNetwork nginx

Connecting a Container to a Network When it Starts

docker run -it -d --network=MyOverlayNetwork nginx

Disconnecting a Container from a Network

docker network disconnect MyOverlayNetwork nginx


Cleaning Docker

Removing a Running Container

docker rm nginx

Removing a Container and its Volume

docker rm -v nginx

Removing 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 nginx

Removing Dangling Images

docker rmi $(docker images -f dangling=true -q)

Removing all Images

docker rmi $(docker images -a -q)

Removing all untagged images

docker rmi -f $(docker images | grep "^<none>" | awk "{print $3}")

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)

Installing Docker Swarm

curl -ssl | bash

Initializing the Swarm

docker swarm init --advertise-addr

Getting a Worker to Join the Swarm

docker swarm join-token worker

Getting a Manager to Join the Swarm

docker swarm join-token manager

Listing Services

docker service ls

Listing nodes

docker node ls

Creating a Service

docker service create --name vote -p 8080:80 instavote/vote

Listing Swarm Tasks

docker service ps

Scaling a Service

docker service scale vote=3

Updating a Service

docker service update --image instavote/vote:movies vote
docker service update --force --update-parallelism 1 --update-delay 30s nginx
docker service update --update-parallelism 5--update-delay 2s --image instavote/vote:indent vote
docker service update --limit-cpu 2 nginx
docker service update --replicas=5 nginx


Stay in the Loop

Get the weekly email from TechLifeTravel that makes reading the news actually enjoyable. Join our mailing list to stay in the loop to stay informed, for free.