Docker Commands Quick Reference Cheat Sheet

Updated by Linode Written by Linode

Contribute on GitHub

Report an Issue | View File | Edit File

Docker Commands Quick Reference Cheat Sheet

Docker is becoming increasingly popular among software developers, operators and enterprises as a software container platform. Containers package software in a format that can run isolated on a host operating system. Bundled with only essential libraries and settings, Docker renders lightweight, efficient, self-contained systems that run identically wherever deployed.

Optimizing the platform’s functionality begins with mastery of the core Docker commands. This cheat sheet is a reference for the most basic Docker commands that address installation, Hub interaction, and working with containers and images.

As of this writing, the recommended Docker installation is Docker Community Edition (Docker CE). See the official docs or our How to Install Docker guide for more details.

If you have not added your limited user account to the docker group (with sudo usermod -aG docker username), all of the commands in this cheatsheet will need to be run with sudo.

Docker Hub

Docker SyntaxDescription
docker search searchtermSearch Docker Hub for images.
docker pull user/imageDownloads an image from Docker Hub.
docker loginAuthenticate to Docker Hub
(or other Docker registry).
docker push user/imageUploads an image to Docker Hub.
You must be authenticated to run this command.

Image and Container Information

Docker SyntaxDescription
docker psList all running containers.
docker ps -aList all container instances, with their ID
and status.
docker imagesLists all images on the local machine.
docker history user/imageLists the history of an image.
docker logs [container name or ID]Displays the logs from a running container.
docker port [container name or ID]Displays the exposed port of a running container.
docker diff [container name or ID]Lists the changes made to a container.

Work With Images and Containers

Docker SyntaxDescription
docker run -it user/imageRuns an image, creating a container and
changing the terminal
to the terminal within the container.
docker run -p $HOSTPORT:$CONTAINERPORT -d user/imageRun an image in detached mode
with port forwarding.
ctrl+p then ctrl+qFrom within the container’s command prompt,
detach and return to the host’s prompt.
docker attach [container name or ID]Changes the command prompt
from the host to a running container.
docker start [container name or ID]Start a container.
docker stop [container name or ID]Stop a container.
docker rm -f [container name or ID]Delete a container.
docker rmiDelete an image.
docker tag user/image:tag user/image:newtagAdd a new tag to an image.
docker exec [container name or ID] shell commandExecutes a command within a running container.

Image Creation

Docker SyntaxDescription
docker commit user/imageSave a container as an image.
docker save user/imageSave an image to a tar archive.
docker build -t sampleuser/ubuntu .Builds a Docker image
from a Dockerfile
in the current directory.
docker loadLoads an image from file.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Join our Community

Find answers, ask questions, and help others.

comments powered by Disqus

This guide is published under a CC BY-ND 4.0 license.