Cheat Sheet with Docker Commands

Original author: Aymen El Amri
  • Transfer
Note perev. : A week ago, Aymen El Amri, who runs eralabs and created the Painless Docker training course, published his Docker Cheat Sheet, a cheat sheet for basic Docker commands. The Git repository of this document on GitHub has already scored 1000+ stars and several third-party contributors, which confirmed its relevance and usefulness.

The commands presented here are described minimally (with an emphasis on readability as is) and include installing Docker, working with registries and repositories, containers, images, network, Docker Swarm. Below is the translation of the crib in its state on September 2 with additions from the comments below.



curl -sSL | sh


Download dmg from this link:


Use the MSI installer:

Docker registries and repositories

Register entry

docker login

docker login localhost:8080

Registry exit

docker logout

docker logout localhost:8080

Image search

docker search nginx

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

Pull (unload from the registry) image

docker pull nginx

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

Push (upload to registry) image

docker push eon01/nginx

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

First steps with containers

Container creation

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

Container first launch

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

Rename container

docker rename infinite infinity

Container removal

docker rm infinite

Container update

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

Starting and stopping containers

Starting a stopped container

docker start nginx


docker stop nginx


docker restart nginx

Pause (pause all container processes)

docker pause nginx


docker unpause nginx

Lock (until the container stops)

docker wait nginx

Sending SIGKILL (final signal)

docker kill nginx

Sending another signal

docker kill -s HUP nginx

Connect to an existing container

docker attach nginx

Getting Container Information

Working containers

docker ps

docker ps -a

Container logs

docker logs infinite

Container Information

docker inspect infinite

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

Container events

docker events infinite

Public ports

docker port infinite

Running processes

docker top infinite

Resource usage

docker stats infinite

Changes to files or directories on the container file system

docker diff infinite

Image management

List of images

docker images

Image creation

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 - .

Delete image

docker rmi nginx

Loading repository into tar (from file or standard input)

docker load < ubuntu.tar.gz

docker load --input ubuntu.tar

Saving an image to a tar archive

docker save busybox > ubuntu.tar

View image history

docker history

Creating an image from a container

docker commit nginx

Image tagging

docker tag nginx eon01/nginx

Push (upload to registry) image

docker push eon01/nginx


Network creation

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=" \

Delete network

docker network rm MyOverlayNetwork

Network List

docker network ls

Retrieving Network Information

docker network inspect MyOverlayNetwork

Connect a running container to the network

docker network connect MyOverlayNetwork nginx

Connecting the container to the network when it starts

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

Disconnecting a container from the network

docker network disconnect MyOverlayNetwork nginx

Docker Cleanup

Removing a running container

docker rm nginx

Removing a container and its volume (volume)

docker rm -v nginx

Delete all containers with exited status

docker rm $(docker ps -a -f status=exited -q)

Delete all stopped containers

docker container prune

docker rm `docker ps -a -q`

Removing containers stopped more than 24 hours ago

docker container prune --filter "until=24h"

Delete image

docker rmi nginx

Removing unused (dangling) images

docker image prune

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

Removing unused (dangling) images even with tags

docker image prune -a

Delete all images

docker rmi $(docker images -a -q)

Delete all images without tags

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

Stop and delete all containers

docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)

Removing unused (dangling) volumes

docker volume prune

docker volume rm $(docker volume ls -f dangling=true -q)

Removing unused (dangling) volumes by filter

docker volume prune --filter "label!=keep"

Removing unused networks

docker network prune

Delete all unused objects

docker system prune

By default for Docker 06.17.1+ volumes are not deleted. To leave, and they too:
docker system prune --volumes

Docker swarm

Install Docker Swarm

curl -ssl | bash

Note perev. : In Docker versions 1.12.0+, nothing additional is required to be installed, because Docker Swarm is built into the Docker Engine as a special mode (Swarm mode).

Initializing Swarm

docker swarm init --advertise-addr

Connecting a worker node to Swarm

docker swarm join-token worker

Connecting a manager node to Swarm

docker swarm join-token manager

List of services

docker service ls

List of nodes

docker node ls

Service Creation

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

Swarm Task List

docker service ps

Service scaling

docker service scale vote=3

Service Update

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


Note perev. : Let me remind you that the original (English) version of the Docker Cheat Sheet is available and updated in the Git repository . The author will be happy with corrections / additions from the community.

Read also in our blog:

Also popular now: