Skip to content
📖 Docker CheatSheets In A4
Branch: master
Clone or download
Latest commit e621123 Apr 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
Dockerfile-example-multiline Dockerfile with multiple lines Mar 4, 2019
README.org docker cheatsheet Apr 18, 2019
cheatsheet-docker-A4.pdf docker cheatsheet Apr 18, 2019
container-install-devkit.sh
delete-all-containers.sh add scripts Nov 23, 2018
delete-unused-images.sh add scripts Nov 23, 2018
install-old-docker.md
sample-mount-file.yml add scripts Nov 23, 2018

README.org

1 Docker CheatSheet

linkedin
github
slack


PRs Welcome

File me Issues or star this repo.

1.1 Container Runtime

NameSummary
dockerd
containerd
cri-oFrom Redhat
rkta pod-native container engine for Linux.
Amazon ACSsupports DC/OS, Swarm, Kubernetes
CoreOS Fleet
Cloud Foundry DiegoNot actively maintained any more
ReferenceCheatSheet: Docker, CheatSheet: CRI-O, CheatSheet: rkt, CheatSheet: containerd

1.2 Docker Basic

NameSummary
Install docker on Ubuntuapt-get install docker.io
Install old docker versionGitHub: install-old-docker.md

1.3 Docker start service

NameSummary
Start a ubuntu test envdocker run ubuntu:16.04 /bin/echo hello world
Start a ubuntu 18.04 test envdocker run ubuntu:18.04 /bin/echo hello world
Start a debian9 test envdocker run debian:9 /bin/echo hello world
Start a centos test envdocker run centos:centos6 /bin/echo hello world
Start a jenkins serverdocker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
Start a nginx serverdocker run -t -d -p 8080:80 --name nginx-test nginx
Start a nexus serverdocker run -d -p 8082:8081 --name nexus -v /data/nexus-data:/nexus-data sonatype/docker-nexus3
Start a sshd serverdocker run -t -d --privileged -p 5022:22 denny/sshd:latest /usr/sbin/sshd -D
Start a ftp serverdocker run -t -d -p 21:21 -p 20:20 -e USERNAME=${username} -e PASSWORD=${password} denny/proftproftpd:v1

1.4 Container Basic

NameSummary
Start docker containerdocker run -p 4000:80 imgname
Start docker container in detached modedocker run -d -p 4000:80 imgname
Start container with entrypoint changed=docker run -t -d –entrypoint=/bin/sh “$docker_image”=
Enter a running containerdocker exec -it <container-id> sh
Upload local file to container filesystemdocker cp /tmp/foo.txt mycontainer:/foo.txt
Download container file local filesystemdocker cp mycontainer:/foo.txt /tmp/foo.txt
Stop containerdocker stop <hash>
Remove containerdocker rm <hash>
Remove all containersdocker rm $(docker ps -a -q)
Force shutdown of one given containerdocker kill <hash>
Login to docker hubdocker login
Tag <image>docker tag <image> username/repo:tag
Docker push a tagged image to repodocker push username/repo:tag
Run image from a given tagdocker run username/repo:tag
Create docker imagedocker build -t denny/image:test .

1.5 Docker Cleanup

NameSummary
Delete all containersdelete-all-containers.sh
Remove unused docker imagesdelete-unused-images.sh
Remove the specified imagedocker rmi <imagename>
Remove all docker imagesdocker rmi $(docker images -q)
Remove orphaned docker volumesdocker volume rm $(docker volume ls -qf dangling=true)
Remove dead containersdocker rm $(docker ps --filter status=dead -qa)
Remove exited containersdocker rm $(docker ps --filter status=exited -qa)

1.6 Dockerfile

NameSummary
Change entrypoint to run nothingentrypoint: ["tail", "-f", "/dev/null"]
Set timezone in DockerfileRUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Define multiple line commandGitHub: Dockerfile-example-multiline

1.7 Docker Compose

NameSummary
Change restart policyrestart: always, Link: Compose file version 3 reference
Mount file as volume$PWD/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro GitHub: sample-mount-file.yml
Start compose envdocker-compose up, docker-compose up -d
Stop compose envdocker-compose down, docker-compose down -v
Check logsdocker-compose logs

1.8 Docker Containers

NameSummary
Start docker containerdocker run -p 4000:80 <imgname>
Start docker container in detached modedocker run -d -p 4000:80 imgname
Start docker container and remove when exitdocker run -rm -it <imgname> sh
Enter a running containerdocker exec -it [container-id] sh
Stop containerdocker stop <hash>
List all containersdocker ps, docker ps -a
Remove containerdocker rm <hash>, docker rm $(docker ps -a -q)
Force shutdown of one given containerdocker kill <hash>
Login to docker hubdocker login
Run image from a given tagdocker run username/repo:tag
Tail container logsdocker logs --tail 5 $container_name
Check container healthcheck statusdocker inspect --format '{{.State.Health}}' $container_name
List containers by labels=docker ps –filter “label=org.label-schema.group”=

1.9 Docker Images

NameSummary
List all imagesdocker images, docker images -a
Create docker imagedocker build -t denny/image:<tag> .
Docker push a tagged image to repodocker push denny/image:<tag>
Show the history of an imagedocker history <image_name>
Export image to filedocker save <image_name> > my_img.tar
Load image to local registrydocker load -i my_img.tar
Tag <image>docker tag <image> username/repo:tag

1.10 Docker Socket file

NameSummary
Run container mounting socket filedocker run -v /var/run/docker.sock:/var/run/docker.sock -it alpine sh
A different docker socket fileexport DOCKER_HOST=unix:///my/docker.sock
List containerscurl -XGET --unix-socket /var/run/docker.sock http://localhost/containers/json
Stop containercurl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers/<container_id>/stop
Start containercurl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers/<container_id>/start
List eventscurl --unix-socket /var/run/docker.sock http://localhost/events
Create containercurl -XPOST --unix-socket /var/run/docker.sock -d '{"Image":"nginx:alpine"}' -H 'Content-Type: application/json' http://localhost/containers/create
LinksLink: Develop with Docker Engine SDKs and API

1.11 Docker Conf

NameSummary
Docker files/var/lib/docker, /var/lib/docker/devicemapper/mnt
Docker for Mac~/Library/Containers/com.docker.docker/Data/

1.12 Ubuntu docker: Install missing packages

NameSummary
Pull ubuntu docker imagedocker pull ubuntu
man: command not foundapt-get update, apt-get install man
ping: command not foundapt-get update, apt-get install iputils-ping
dig: command not foundapt-get install dnsutils

1.13 Check Status

NameSummary
Tail container logsdocker logs --tail 5 $container_name
Check container healthcheck statusdocker inspect --format '{{.State.Health}}' $container_name
List containersdocker ps
List all containersdocker ps -a
List containers by labels=docker ps –filter “label=org.label-schema.group”=
List all imagesdocker images -a

1.14 Resource Reference

NameSummary
Docker SDKhttps://docs.docker.com/develop/sdk/examples/
Docker REST APIhttps://docs.docker.com/engine/api/v1.27/#tag/Container
Docker Hub auto buildhttps://docs.docker.com/docker-hub/builds/#build-statuses-explained

1.15 More Resources

License: Code is licensed under MIT License.

linkedin github slack
You can’t perform that action at this time.