Show Menu

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]
remove container on exit
add container ID
set enviro­nment variable
publish container ports to host
connect container to network
network scoped alias for the container
container in background / detached
run intera­ctively
-v $(pwd)­:/app
map the pwd into the '/app' folder
Start an existing Container
docker container start [conta­iner]
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
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


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


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]


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

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
- rebuild container
detach­/launch in background
Stop and Remove system
docker­-co­mpose down
List containers
docker­-co­mpose ps