Show Menu

Docker commands Cheat Sheet by

Basic Docker Commands

docker search
Search Docker Hub for images
docker pull
Downloads an image from Docker Hub
docker login
Authen­ticate to Docker Hub (or other Docker registry)
docker push
Uploads an image to Docker Hub. You must be authen­ticated to run this command
docker info
Retrieves docker config­​ur­ation
docker version
Retrieves docker versioning

Image and Container Inform­ation

docker ps
List all running containers
docker ps -a
List all container instances, with their ID and status
docker images
Lists all images on the local machine
docker history <us­er>­/<i­mag­e>
Lists the history of an image
docker logs <co­nta­ine­r>
Displays the logs from a running container
docker port <co­nta­ine­r>
Displays the exposed port of a running container
docker diff <co­nta­ine­r>
Lists the changes made to a container
docker logs [-f] <co­nta­ine­r>
Read container stdout
docker top <co­nta­ine­r>
Show running processes
docker inspect <co­nta­ine­r>
Show container config­­ur­ation
docker events
Show container events
<co­nta­ine­r> can be replaced with container name or ID

Network Commands

docker network ls
List networks
docker network inspect <Ne­​tw­o​r­k>
Inspect a network
docker network create <Ne­​tw­o​r­k>
Create a network
docker network rm <Ne­​tw­o​r­k>
Removes a network
docker network connect <Ne­​tw­o​r­k> <Co­​nt­a​i­ne​­r>
Connect a container to the network
docker network connect --ip <IP> <Ne­​tw­o​r­k> <Co­​nt­a​i­ne​­r>
Specify the IP address of container interface
docker network disconnect <Ne­​tw­o​r­k_​­Nam­​e> <Co­​nt­a​i­ne​­r>
Disconnect container from network
<Ne­​tw­o​r­k> can be replaced with the network ID or NAME

Work With Images and Containers

docker run -it user/image
Runs an image, creating a container and changing the terminal to the terminal within the container
docker run -p <ho­stp­ort­>:<­con­tai­ner­por­t> -d user/image
Run an image in detached mode with port forwarding
docker start <co­nta­ine­r>
Start a container
docker exec <co­nta­ine­r> [shell command]
Executes a command within a running container, e.g. /bin/bash
docker attach <co­nta­ine­r>
Changes the command prompt from the host to a running container
docker stop <co­nta­ine­r>
Stop a container
docker rm -f <co­nta­ine­r>
Delete a container
docker create <im­age­>:<­tag>
Create image
docker rmi <im­age>
Delete an image
docker tag <us­er>­/<i­mag­e>:­<ta­g> <us­er>­/<i­mag­e>:­<new tag>
Add a new tag to an image
ctrl+p then ctrl+q
Changes the command prompt from the host to a running container
<co­nta­ine­r> can be replaced with container name or ID

Misc. Examples

sudo docker commit contai­nterID userna­me/­ima­gename
Commit from container to an image
docker push userna­me/­ima­gename
Docker push example (after logging)
docker run -it -v /host/­dir­ect­ory­:/c­ont­ain­er/­dir­ectory [options] image [command]
Mount a host directory in a Docker container
docker cp /host/­dir­ect­ory­/fi­le.ext container:/cont­ain­er/­dir­ectory
Copy file from host machine to docker container
docker rmi $(docker images -a -q)
Delete all Docker images
docker rm $(sudo docker ps -a -q)
Delete all stopped containers
docker rm $(sudo docker ps -a | grep Exit | cut -d ' ' -f 1)
Delete all containers in Exit state
docker save imagename > filename.tar
Export image to a file
docker load < filename.tar
Load image from file
docker [command] --help
Command help

Options Keywords

-p, –-publish
Host to container port mapping
Publish all ports
-d, –-detach
Run in background
-e, –-env
Set env vars
-v, --volume
Mount files or direct­­ories


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Basic Cisco IOS Commands Cheat Sheet
          Docker Cheat Sheet