Docker Commands Cheat Sheet
Docker Commands Cheat Sheet
Name Summary
Docker push: manifest invalid Re-push a new version of the same docker tag may fail, due to permis
Docker pull: missing signature key Docker push again to resolve the issue
Docker cp: Error response from daemon: not a directory container folder is in a symbol link
Find process id by container name docker top $container_id, or docker top $container_name
List resource usage by containers docker stats
Get dockerd storage driver docker info, then check Storage Driver
docker-containerd-shim The Docker four components: Docker engine, containerd, containe
Name Summary
Start a ubuntu test env docker run ubuntu:16.04 /bin/echo hello world
Start a ubuntu 18.04 test env docker run ubuntu:18.04 /bin/echo hello world
Start a container run and stop docker run --rm ubuntu:18.04 /bin/echo hello world
Start a debian9 test env docker run debian:9 /bin/echo hello world
Start a centos test env docker run centos:centos6 /bin/echo hello world
Start a jenkins server docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
Start a nginx server docker run -t -d -p 8080:80 --name nginx-test nginx
Start a mysql server docker run -e MYSQL_ROOT_PASSWORD=password123 -e MYSQL_DATABASE=wordpress -d mys
Start a nexus server docker run -d -p 8082:8081 --name nexus -v /data/nexus-data:/nexus-data sonatype
Start a sshd server docker run -t -d --privileged -p 5022:22 denny/sshd:latest /usr/sbin/sshd -D
Start a ftp server docker run -t -d -p 21:21 -p 20:20 -e USERNAME=${username} -e PASSWORD=${passwor
GitHub: https://github.com/dennyzhang/cheatsheet-docker-A4 1 of 4
Blog URL: https://cheatsheet.dennyzhang.com/cheatsheet-docker-A4 Updated: June 14, 2020
1.7 Dockerfile
Name Summary
Change entrypoint to run nothing entrypoint: ["tail", "-f", "/dev/null"]
Set timezone in Dockerfile RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezon
Define multiple line command GitHub: Dockerfile-example-multiline
Name Summary
Change restart policy restart: 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 env docker-compose up, docker-compose up -d
Stop compose env docker-compose down, docker-compose down -v
Check logs docker-compose logs
GitHub: https://github.com/dennyzhang/cheatsheet-docker-A4 2 of 4
Blog URL: https://cheatsheet.dennyzhang.com/cheatsheet-docker-A4 Updated: June 14, 2020
Name Summary
Start docker container docker run -p 4000:80 <imgname>
Start docker container in detached mode docker run -d -p 4000:80 imgname
Start docker container and remove when exit docker run -rm -it <imgname> sh
Enter a running container docker exec -it [container-id] sh
Stop container docker stop <hash>
List all containers docker ps, docker ps -a
Remove container docker rm <hash>, docker rm $(docker ps -a -q)
Force shutdown of one given container docker kill <hash>
Login to docker hub docker login
Run image from a given tag docker run username/repo:tag
Tail container logs docker logs --tail 5 $container_name
Check container healthcheck status docker inspect --format ’{{.State.Health}}’ $container_name
List containers by labels docker ps --filter "label=org.label-schema.group"
Name Summary
Run container mounting socket file docker run -v /var/run/docker.sock:/var/run/docker.sock -it alpine sh
A different docker socket file export DOCKER_HOST=unix:///my/docker.sock
List containers curl -XGET --unix-socket /var/run/docker.sock http://localhost/containers/jso
Stop container curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers/<c
Start container curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers/<c
List events curl --unix-socket /var/run/docker.sock http://localhost/events
Create container curl -XPOST --unix-socket /var/run/docker.sock -d ’{"Image":"nginx:alpine"}’
Links Link: Develop with Docker Engine SDKs and API
GitHub: https://github.com/dennyzhang/cheatsheet-docker-A4 3 of 4
Blog URL: https://cheatsheet.dennyzhang.com/cheatsheet-docker-A4 Updated: June 14, 2020
GitHub: https://github.com/dennyzhang/cheatsheet-docker-A4 4 of 4