Show Menu
Cheatography

Docker Cheat Sheet (DRAFT) by

docker cheat sheet for learning

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

Basic Docker Commands

docker ps
List of live containers
docker ps -a
List all containers
docker info
Retrieves docker config­uration
docker version
Retrieves docker versioning
docker build -t <Im­age­>:<­Tag> .
Builds a docker Image from Dockerfile or container
docker push <Im­age­_Na­me>­:<T­ag>
Pushes the image to the repo
docker pull <Im­age­_Na­me>­:<T­ag>
Pulls the image from the repo

Container Commands

docker inspect <Co­nta­ine­r>
Inspect a container
docker stats <Co­nta­ine­r>
Live data stream from container
docker logs <Co­nta­ine­r>
Retrieves the containers logs
docker run <Co­nta­ine­r>
Run container
docker kill <Co­nta­ine­r>
Kill a running container
docker start <Co­nta­ine­r>
Start container
docker stop <Co­nta­ine­r>
Stop a running container
docker restart <Co­nta­ine­r>
Restarts the container
docker rm <Co­nta­ine­r>
Remove container
docker port <Co­nta­ine­r>
Lists the port mapping of the container
docker pause <Co­nta­ine­r>
Suspends all the processes in the container
docker unpause <Co­nta­ine­r>
Un-sus­pends all the processes in the container
<Co­nta­ine­r> can be replaced with the containers ID or NAME

Options Keywords

-p, –-publish
Host to container port mapping
--publ­ish-all
Publish all ports
--expose
Expose container port
-d, –-detach
Run in background
-e, –-env
set env vars
-v, --volume
Mount files or direct­ories
-i, --inte­ractive
attach stdin
-t, --tty
pseudo­-te­letype
exec
Run a new command in a container
cp
copy path
These options keywords can be add to most docker commands
 

Volume Commands

docker volume ls
List volumes
docker volume inspect <Vo­lum­e>
Inspect volume
docker volume create <Vo­lum­e>
Create volume
docker volume rm <Vo­lum­e>
Removes a volume
<Vo­lum­e> can be replaced with the volume ID or NAME

Image commands

docker images
List images
docker run <Im­age>
runs the image
docker create <Im­age­>:<­Tag>
Create image
docker rmi <Im­age>
Remove image
docker save <Im­age>
Saves images to a tar archive

Network Commands

docker network ls
List networks
docker network inspect <Ne­two­rk>
Inspect a network
docker network create <Ne­two­rk>
Create a network
docker network rm <Ne­two­rk>
Removes a network
docker network connect <Ne­two­rk> <Co­nta­ine­r>
Connect a container to the network
docker network connect --ip <IP> <Ne­two­rk> <Co­nta­ine­r>
Specify the ip address of container interface
docker network disconnect <Ne­two­rk_­Nam­e> <Co­nta­ine­r>
Disconnect container from network
<Ne­two­rk> can be replaced with the network ID or NAME

Misc. Commands

docker cp <Co­nta­ine­r>:­<so­urc­e_p­ath> <de­st_­pat­h>
Copy from container to host
docker cp <so­urc­e_p­ath> <Co­nta­ine­r>:­<de­st_­pat­h>
Copy from host to container
docker exec -ti <Co­nta­ine­r> <En­try­poi­nt>
Executes the terminal of a live container