Show Menu
Cheatography

DOCKER Cheat Sheet (DRAFT) by

DEVOPS: DOCKER CHEAT SHEET

This is a draft cheat sheet. It is a work in progress and is not finished yet.

DOCKER

Docker is an open source platform for building, deploying, and managing contai­nerized applic­ations.

DOCKER IMAGES

Download an image
docker pull nginx
Upload an image to a repository
docker push myimag­e:1.0
Delete an image
docker rmi nginx
Show a list of all Images
docker images
Delete dangling images
docker image prune
Build an image from a Dockerfile
docker build .
Tag an image
docker tag ubuntu ubuntu­:18.04
Save an image
docker save nginx > nginx.tar
Load an image from a .tar file
docker load -i nginx.tar

RUN CONTAINERS

Start a new Container from an Image
docker run nginx
Assign it a name
docker run --name web nginx
Map a port
docker run -p 8080:80 nginx
Map all ports
docker run -P nginx
Start container in background
docker run -d nginx
Assign it a hostname
docker run --hostname srv nginx
 

MANAGE CONTAINERS

Show a list of running containers
docker ps
Show a list of all containers
docker ps -a
Delete a container
docker rm web
Delete a running container
docker rm -f web
Delete stopped containers
docker container prune
Stop a running container
docker stop web
Start a stopped container
docker start web
Create an image out of container
docker commit web

NETWORK

List networks
docker network ls
Create a local network
docker network create mynet
Show Inform­ation on one or more networks
docker network inspect (network)
Connect a container to a network
docker network connect (network) (conta­iner)
Disconnect a container from a network
docker network disconnect (network) (conta­iner)
 

DOCKER COMPOSE

Start your docker­-co­mpose defined resources in detached mode
docker­-co­mpose up -d -f <do­cke­r_c­omp­ose­_ya­ml>
Stop all docker­-co­mpose resources
docker­-co­mpose stop
Destroy all docker­-co­mpose resources
docker­-co­mpose down

ORCHES­TRATE

Initialize swarm
Docker swarm init --adve­rti­se-addr IP
Join an existing swarm as manage­r/w­orker node
Docker swarm join --toke­n<m­ana­ger­-to­ken> IP
Docker swarm join --toke­n<w­ork­er-­tok­en> IP
Create a service
Docker service create --replicas 3 -p 80:80 --name web nginx

DOCKER MACHINE

Create a machine
docker­-ma­chine create --driver VirtualBox NAME
List all the machines
docker­-ma­chine ls
Connect to a machine
docker­-ma­chine ssh NAME
 

VOLUMES

List volumes
docker volume ls
Create a volume
docker volume create <vo­lum­e>
Delete a volume
docker volume rm <vo­lum­e>
Mount a local directory to your container
docker run -v <lo­cal­_di­r>:/<co­nta­ine­r_d­ir> <im­age>

TROUBL­ESH­OOTING

Show the logs of a container
docker logs <co­nta­ine­r>
Show a 'top' view of processes running on a container
docker top <co­nta­ine­r>
Show any files that have changed since startup
docker diff <co­nta­ine­r>
Connect to an already running container
docker attach <co­nta­ine­r>
Execute a command on a container
docker exec -it <co­nta­ine­r_i­d> /bin/bash
Show docker disk space used
docker system df