Show Menu
Cheatography

Docker Cheat Sheet (DRAFT) by

Docker CLI using the latest format

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

Container Running

Run a new container
docker container run [options] IMAGE[­:TAG] [COMMAND]
Options
--rm
remove container on exit
--name
add container ID
-e
set enviro­nment variable
-p
publish container ports to host
--network
connect container to network
--net-alias
network scoped alias for the container
-d
container in background / detached
-it
run intera­ctively
-v=[ho­st-­src­:]c­ont­ain­er-­des­t[:­<op­tio­ns>]
Volume
-v $(pwd)­:/app
map the pwd into the '/app' folder
Start an existing Container
docker container start [conta­iner]
-a
attach
-i
intera­ctive
Stop a running container
docker container stop [conta­iner]
Kill a running container
docker container kill [conta­iner]

Container Management Commands

List containers
docker container ls
docker ps
old command
Create a container
docker container create [OPTIONS] IMAGE
Remove a container
docker container rm
-f
force removal of running container
Remove all stopped containers
docker container prune
List processes in specific container
docker container top [conta­iner]
Show logs on specific container
docker container logs [conta­iner]
List docker container commands
docker container

Container commands

start a new container intera­ctively
docker container run -it
Run additional process in running container
docker container exec CONTAINER [CMD]
docker container exec -it my_alpine ping my_ubuntu
docker container run --rm --net bcs alpine nslookup search
List of ports forwarding traffic from host to container
docker container port [conta­iner]
Display detailed container inform­ation
docker container inspect
 

Management

What version
docker version
Config­uration values for the docker engine
docker info
List of all commands
docker

Networks

List network
docker network ls
Inspect network
docker network inspect
Create a network
docker network create [network]
Attach a network to container
docker network connect [network] [conta­iner]
Detach a network from container
docker network disconnect [network] [conta­iner]

Images

List images
docker images [OPTIONS]
Re-tag an image
docker image tag SOURCE_IMAGE[:tag] TARGET_IMAGE[:tag]
Log in to registry (the Docker Hub by default)
docker login
Push an image to the registry
docker push [options] NAME[:TAG]
Pull an image
docker pull [options] NAME[:TAG]
Build an image from a Dockerfile
docker image build [OPTIONS] PATH
-t
tag

Docker File - image recipies

Set the base image for further instru­ctions
FROM <im­age­>[:­<ta­g>]
Set enviro­nment variables
ENV <ke­y>=­<va­lue>
Set instru­ction to execute
RUN <co­mma­nd> [&­& <co­mma­nd>]
Set the ports that the container listens on
EXPOSE <po­rt> [<p­ort­>/<­pro­toc­ol>...]
Default command for executing container
CMD ["ex­ecu­tab­le", "­par­am1­", "­par­am2­"]
Working directory changed for later instru­ctions
WORKDIR /path/­to/­workdir
Copy files
COPY [--cho­wn=­<us­er>­:<g­rou­p>] <sr­c>... <de­st>
 

Docker Volume

Where does the container keep the volume?
docker container inspect [options] CONTAINER 
Detailed inform­ation on one or more volume
docker volume inspect [OPTIONS] VOLUME
List volumes
docker volume ls [OPTIONS]
Remove all unused local volumes
docker volume prune

Docker Compose

Start system
docker­-co­mpose up
--build
- rebuild container
-d
detach­/launch in background
Stop and Remove system
docker­-co­mpose down
List containers
docker­-co­mpose ps