Skip to content

Instantly share code, notes, and snippets.

@awsvpc
Forked from mbadley/docker-cheat-sheet.txt
Created February 8, 2026 21:26
Show Gist options
  • Select an option

  • Save awsvpc/dfba942f44dc19b4794fc8d4c037cc30 to your computer and use it in GitHub Desktop.

Select an option

Save awsvpc/dfba942f44dc19b4794fc8d4c037cc30 to your computer and use it in GitHub Desktop.
Docker Cheat Sheet
docker login registry.XXXX.com with new container
docker pull registry.XXXX..com/nativ/base-microservice:latest
#ID of the last-run Container
docker ps -l -q (aliased to dl)
#list images
docker images
#list all containers
docker ps -a
#create a container but do not run it
docker create
#run an image (:latest can be a tag)
#creates a new container from the image & run it
docker run -t -i registry.XXXX.com/nativ/base-microservice:latest /bin/bash
#create container web1 from image called image & map port 80 to 8081 which is exposed to the outside world
docker run -d --name web1 -p 8081:80 image
#build an image
docker build -t image . (the . is the location of the Docker file)
#create a container
docker run -d --name ssh.pool-1.1.1 -p 2020:22 jdeathe/centos-ssh:latest
#list running containers
acfe8bb43f2e jdeathe/centos-ssh:latest
#create a new image
docker run -t -i training/sinatra /bin/bash
gem install json
save changes & exit
docker commit -m "Added json gem" -a "Malcolm Badley" 0b2616b0e5a8 ouruser/sinatra:v2
-m commit message
-a author
0b2616b0e5a8 container to create image from
ouruser/sinatra:v2 - target for image
docker run -t -i ouruser/sinatra:v2 /bin/bash #uses new image
#Building an image from a Dockerfile
mkdir sinatra
cd sinatra
touch Dockerfile
# This is a comment
FROM ubuntu:14.04
MAINTAINER Malcolm Badley <mbadley@ooyala.com>
RUN apt-get update && apt-get install -y ruby ruby-dev
RUN gem install sinatra
docker build -t ouruser/sinatra:v2 .
-t identify our new image as belonging to the ouruser, the repository name sinatra and given it the tag v2
create a container from our new image.
docker run -t -i ouruser/sinatra:v2 /bin/bash
now add an extra tag
docker tag 5db5f8471261 ouruser/sinatra:devel
#start a container & login
docker start 77f2519c5796
docker exec -t -i 77f2519c5796 bash
#view digests
docker images --digests
#login to container
docker exec -it acfe8bb43f2e bash
#login to repository
docker login
#see docker logs
docker logs
#look at all container info eg IP
docker inspect <container ID or name>
#look at events of a container (listens for events)
docker events #present
docker events --since '2013-09-03' #past
docker events --filter 'event=stop' #filter
docker events --since '2013-09-03' --filter 'event=stop' #combine
#look at public facing ports
docker port
#look at processes in a container
docker top
#look at containers' resource usage statistics
docker stats
#look at changed files in the container's FS
docker diff
#upload image to repository
docker push image
#run image uploaded in repo from production machine
docker run -p 80:80 -d --name <container> <image>
#login to docker container repo
docker exec -it artifactory /bin/bash
#copies files or folders between a container and the local filesystem
docker cp
#turns container filesystem into tarball archive stream to STDOUT
docker export
#execute a command in container.
docker exec
#tag images
docker tag centos 9abe35755c39.XXXX..com/docker-test1:latest
#push to artifactory
docker push 9abe35755c39.XXXX.com/docker-test1:latest
#Data volumes are designed to persist data, independent of the container’s life cycle
#create a data volume
mkdir -p /etc/services-config/ssh.pool-1
docker run --name volume-config.ssh.pool-1.1.1 -v /etc/services-config/ssh.pool-1/ssh:/etc/services-config/ssh -v /etc/services-config/ssh.pool-1/supervisor:/etc/services-config/supervisor busybox:latest /bin/true
#add a data volume to a container
docker run -d -P --name web -v /webapp training/webapp python app.py #create a new volume inside a container at /webapp
docker run -d -P --name web -v /opt/webapp:ro training/webapp python app.py #read only
docker inspect web #locate the volume on the host
docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py #mounts the host directory, /src/webapp, into the container at /opt/webapp
docker run -d -P --name web -v /src/webapp:/opt/webapp:ro training/webapp python app.py #mount read only
docker create -v /dbdata --name dbdata training/postgres /bin/true #create a new named container with a volume to share
docker run -d --volumes-from dbdata --name db1 training/postgres #use --volumes-from to mount /dbdata volume in another container
#stop container
docker stop ssh.pool-1.1.1
#remove container
docker rm ssh.pool-1.1.1
#create container & mount with new volume
docker run -d --name ssh.pool-1.1.1 -p :22 --volumes-from volume-config.ssh.pool-1.1.1 jdeathe/centos-ssh:latest
#remove an image
docker rmi dtr.yourdomain.com/ci-infrastructure/jnkns-img
#quick & easy install script
curl -sSL https://get.docker.com/ | sh
#Lifecycle
docker images #shows all images.
docker import #creates an image from a tarball.
docker build #creates image from Dockerfile.
docker commit #creates image from a container, pausing it temporarily if it is running.
docker rmi #removes an image.
docker load #loads an image from a tar archive as STDIN, including images and tags (as of 0.7).
docker save #saves an image to a tar archive stream to STDOUT with all parent layers, tags & versions (as of 0.7).
#Networks
Docker has a networks feature. Not much is known about it, so this is a good place to expand the cheat sheet. There is a note saying that it's a good way to configure docker containers to talk to each other without using ports. See working with networks for more details.
Lifecycle
docker network create
docker network rm
Info
docker network ls
docker network inspect
Connection
docker network connect
docker network disconnect
#Repository
docker login to login to a registry.
docker search searches registry for image.
docker pull pulls an image from registry to local machine.
docker push pushes an image to the registry from local machine.
#create a network
docker network create -d bridge my-bridge-network
#run a container within a network
docker run -d --net=my-bridge-network --name db training/postgres
#Docker networking allows you to attach a container to as many networks as you like
docker network connect my-bridge-network web
#docker hub
https://hub.docker.com
https://hub.docker.com/explore #official repositories
#docker run persistence and create new container
docker run --detach --publish=80:80 --publish=81:81 --publish=8125:8125/udp --publish=8126:8126 --name mdpb-aws0-grafana-dashboard --volume=$(pwd)/data/whisper:/opt/graphite/storage/whisper --volume=$(pwd)/data/elasticsearch:/var/lib/elasticsearch --volume=$(pwd)/data/grafana:/opt/grafana/data --volume=$(pwd)/log/graphite:/opt/graphite/storage/log --volume=$(pwd)/log/elasticsearch:/var/log/elasticsearch kamon/grafana_graphite
docker run --detach --publish=80:80 --publish=81:81 --publish=8125:8125/udp --publish=8126:8126 --name aws0-grafana-dashboard --volume=$(pwd)/data/whisper:/opt/graphite/storage/whisper --volume=$(pwd)/data/elasticsearch:/var/lib/elasticsearch --volume=$(pwd)/data/grafana:/opt/grafana/data --volume=$(pwd)/log/graphite:/opt/graphite/storage/log --volume=$(pwd)/log/elasticsearch:/var/log/elasticsearch mbadley/mdpb-aws0-graf:v4
#docker compose install
curl -L https://github.com/docker/compose/releases/download/1.1.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
curl -L https://raw.githubusercontent.com/docker/compose/1.1.0/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
#sample docker-compose.yml
grafana:
image: kamon/grafana_graphite:latest
restart: always
ports:
- "80:80"
- "81:81"
- "8125:8125/udp"
- "8126:8126"
volumes:
- /opt/graphite/storage/whisper
- /var/lib/elasticsearch
- /var/lib/elasticsearch
- /opt/grafana/data
- /opt/graphite/storage/log
- /var/log/elasticsearch
docker-compose -f docker-compose.yml up -d
#add mbadley to docker group
#get latest images
docker-compose pull
volumes:
- /mio/logstash/config:/config-dir
command: logstash -f /config-dir/*.conf
/mio/logstash/config/logstash.conf <- full configuration
sudo docker tag 871e7a29a38c mbadley/grafana-dashboard:latest
sudo docker push registry.nativ-systems.com/nativ/grafana-dashboard:latest
docker run --detach --publish=80:80 --publish=81:81 --publish=8125:8125/udp --publish=8126:8126 --name kamon-grafana-dashboard mbadley/grafana-dashboard
TAGS
BUILD
cd ~/docker/carbon (must have Dockerfile)
sudo docker build -t registry.XXXX.com/nativ/carbon .
PUSH
sudo docker push registry.XXXX..com/nativ/carbon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment