📜 ⬆️ ⬇️

Cheat Sheet with Docker Teams

Note trans. : 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 the main Docker teams. The Git-repository of this document on GitHub has already gained 1000+ stars and several third-party contributors, which confirmed its relevance and benefit.



The commands presented here are described minimally (with an emphasis on readability as is) and include Docker installation, work with registries and repositories, containers, images, network, Docker Swarm. Below is a translation of the cheat sheet in its condition on September 2, with additions from the comments below.
')

Installation


Linux


curl -sSL https://get.docker.com/ | sh 

Mac


Download the dmg from this link:
 https://download.docker.com/mac/stable/Docker.dmg 

Windows


Use the MSI installer:
 https://download.docker.com/win/stable/InstallDocker.msi 

Docker Registries and Repositories


Registry entry


 docker login 

 docker login localhost:8080 

Exit registry


 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 (load into the 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 

First run of the container


 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


Running a stopped container


 docker start nginx 

Stop


 docker stop nginx 

Reboot


 docker restart nginx 

Pause (suspend all container processes)


 docker pause nginx 

Remove pause


 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 information about containers


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 in files or directories in the container's file system


 docker diff infinite 

Image Management


List of images


 docker images 

Creating images


 docker build . 

 docker build github.com/creack/docker-firefox 

 docker build - < Dockerfile 

 docker build - < context.tar.gz 

 docker build -t eon/infinite . 

 docker build -f myOtherDockerfile . 

 curl example.com/remote/Dockerfile | docker build -f - . 

Deleting an image


 docker rmi nginx 

Loading repository to tar (from file or standard input)


 docker load < ubuntu.tar.gz 

 docker load --input ubuntu.tar 

Saving the image to a tarball


 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 (load into the registry) image


 docker push eon01/nginx 

Network


Networking


 docker network create -d overlay MyOverlayNetwork 

 docker network create -d bridge MyBridgeNetwork 

 docker 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 

Network removal


 docker network rm MyOverlayNetwork 

Network List


 docker network ls 

Retrieving network information


 docker network inspect MyOverlayNetwork 

Connecting a working 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 the container from the network


 docker network disconnect MyOverlayNetwork nginx 

Cleaning docker


Removing a working container


 docker rm nginx 

Deleting a container and its 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 a day ago


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

Deleting an image


 docker rmi nginx 

Removing unused (dangling) images


 docker image prune 

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

Delete 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 

Deleting all unused objects


 docker system prune 

Docker 17.06.1+ does not delete volumes by default. To retire and they too:
 docker system prune --volumes 

Docker swarm


Install Docker Swarm


 curl -ssl https://get.docker.com | bash 

Note trans. : Docker version 1.12.0+ doesn’t need anything extra Docker Swarm is built into the Docker Engine as a special mode (Swarm mode).

Swarm Initialization


 docker swarm init --advertise-addr 192.168.10.1 

Connecting the worker node (worker) to Swarm


 docker swarm join-token worker 

Connecting the control node (manager) to Swarm


 docker swarm join-token manager 

List of services


 docker service ls 

List of nodes


 docker node ls 

Creating a service


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

Swarm Task List


 docker service ps 

Scaling service


 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 

PS


Note trans. : Let me remind you that the original (English-language) version of 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:

Source: https://habr.com/ru/post/336654/


All Articles