Show Menu
Cheatography

Docker Cheat Sheet (DRAFT) by

Commands for Docker. Commands for Docker

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

Run a new container

Start a new Container from an Image
docker run IMAGE
...and assign it a name
docker run --name CONTAINER IMAGE
...and map a port
docker run -p HOSTPO­RT:­CON­TAI­NERPORT IMAGE
...and map all ports
docker run -P IMAGE
...and start container in background
docker run -d IMAGE
...and assign it a hostname
docker run --hostname HOSTNAME IMAGE
...and add a dns entry
docker run --add-host HOSTNA­ME:IP IMAGE
...and map a local directory into the container
docker run -v HOSTDI­R:T­ARG­ETDIR IMAGE
...but change the entrypoint
docker run -it --entr­ypoint EXECUTABLE IMAGE
 

Manage containers

Show running containers
docker ps
Show all containers
docker ps -a
Delete a container
docker rm CONTAINER
Delete a running container
docker rm -f CONTAINER
Delete stopped containers
docker container prune
Stop a running container
docker stop CONTAINER
Start a stopped container
docker start CONTAINER
Copy from a container to the host
docker cp CONTAI­NER­:SOURCE TARGET
Copy from the host to a container
docker cp TARGET CONTAI­NER­:SOURCE
Start a shell inside a running container
docker exec -it CONTAINER EXECUTABLE
Rename a container
docker rename OLD_NAME NEW_NAME
Create an image out of container
docker commit CONTAINER
 

Manage Images

Download an image
docker pull IMAGE[­:TAG]
Upload an image to a repository
docker push IMAGE
Delete an image
docker rmi IMAGE
Show a list of all Images
docker images
Delete dangling images
docker image prune
Delete all unused images
docker image prune -a
Build an image from a Dockerfile
docker build DIRECTORY
Tag an image
docker tag IMAGE NEWIMAGE
Build and tag an image from a Dockerfile
docker build -t IMAGE DIRECTORY
Save an image to .tar file
docker save IMAGE > FILE
Load an image from a .tar file
docker load -i TARFILE
 

Info & Stats

Show the logs of a container
docker logs CONTAINER
Show stats of running containers
docker stats
Show processes of container
docker top CONTAINER
Show installed docker version
docker version
Get detailed info about an object
docker inspect NAME
Show all modified files in container
docker diff CONTAINER
Show mapped ports of a container
docker port CONTAINER