The Ultimate Docker Cheat Sheet: Everything You Need to Know

Discover the power of Docker with our comprehensive Docker cheat sheet! This resource covers everything from basic commands to more advanced tips and tricks, helping you streamline your workflow and get the most out of containerization.

Updated: 13 Mar, 23 by Susith Nonis 12 Min

List of content you will read in this article:

A Docker image is a ready-to-use software and read-only template containing instructions for creating a container. Docker images can’t be executed alone and can’t run and start without containers. Also, you can easily find hundreds of docker images developed by many users on Docker hub and use them based on your preferences.

As for a container, it’s a runtime instance of a docker image that gets created when the docker’s run command is implemented. Developers can virtualize the operating system and run them everywhere. Put, an image is a snapshot of an environment, and a container runs the software.

As software developers, we’re always looking for the best tools and guides to help us to be more productive. The sections below have everything you need to know about Docker. 

Installation 

All you need to do is download the latest version of Docker from its original website.

For Windows

You can download the Docker for Windows from the link below.

https://download.docker.com/win/stable/InstallDocker.msi

For Linux 

You can download the Docker for Linux from the link below.

https://docs.docker.com/desktop/install/linux-install/

For Mac 

You can download the Docker for Mac from the link below.

https://docs.docker.com/desktop/install/mac-install/

Docker Registry and Repository

A container registry is a repository or collection of repositories that allow you to store and access container images.

Log in to a Registry

This command is used for logging in to your Registry.

Syntax: docker login

docker login localhost:8080

Logout from a Registry

This command is used for logging out from your Registry.

Syntax: docker logout

docker logout localhost:8080

Search an image

This command is used to search any image from your docker.

Syntax: search nginx

docker search --filter stars=3 --no-trunc nginx

Pull an image

This command is used to download a specific image or set of images.

Syntax: docker image pull nginx

docker image pull eon01/nginx localhost:5000/myadmin/nginx

Push an image

This command is used to push a specific image or set of images.

Syntax: docker image push eon01/nginx

docker image push eon01/nginx localhost:5000/myadmin/nginx

Run containers 

Containers are isolated areas that allow engineers to build, test, and deploy applications and services. Developers can run multiple containers at the same time with different images.

Create container 

This command is used to build a container without running it.

Syntax: docker container create -t -i eon01/infinite --name XYZ

Run container 

This command is used to run a container.

Syntax: docker container run -it --name XYZ -d eon01/infinite

Rename container

This command is used to rename a container.

Syntax: docker container rename XYZ infinity

Remove container

This command is used to remove a container.

Syntax: docker container rm infinite

Update container

This command is used to update the container.

Syntax: docker container update --cpu-shares 512 -m 300M infinite

Starting and stopping the container

For several reasons, developers need to stop, restart, pause, and block the container. And the sections below cover every possible scenario.

Start container

This command is used for starting a container.

Syntax: docker container start nginx

Stop container

This command is used for stopping a container.

Syntax: docker container stop nginx

Restart container

This command is used for restarting a container.

Syntax: docker container restart nginx

Pause the container

This command is used for pausing a container.

Syntax: docker container pause nginx

Unpause the container

This command is used for unpausing a container.

Syntax: docker container unpause nginx

Block container

This command is used for blocking a container.

Syntax: docker container wait nginx

Send a SIGKILL

This command is used for sending a SIGKILL.

Syntax: docker container kill nginx

Send another signal

This command is used for sending another signal.

Syntax: docker container kill -s HUP nginx

Connect to an existing container.

This command is used to connect to an existing container.

Syntax: docker container attach nginx

Acquiring container information 

These commands provide developers with detailed information on Constructs by docker.

Obtain information from the running container.

This command is used to obtain information from the running container.

Syntax: docker ps or docker container ls

Obtain information from every container.

This command is used to obtain information from every container.

Syntax: docker container ls -a or docker ps -a

Check the container’s log

This command is used to see the container’s log.

Syntax: docker logs infinite

Inspect container

This command is used to inspect containers.

Syntax: docker container inspect infinite, or docker container inspect --format '' $(docker ps -q)

Obtain real-time container events

This command is used to obtain real-time events from the server.

Syntax: docker system events infinite

Find public ports

This command is used to find a public port.

Syntax: docker container port infinite

Display Running processes

This command is used to display the running processes in the container.

Syntax: docker container top infinite

Display container resources usage

This command displays a live stream of resource usage statics for containers.

Syntax: docker container stats infinite

Inspect changes to files on the container’s filesystem

This command inspects changes to files or directories on a container’s filesystem.

Syntax: docker container diff infinite

Managing docker images

Docker image is ready-to-use software and includes everything you need to run an application or service.

List images

This command is used to list images.

Syntax: docker image ls

Create images from the current directory. 

This command creates images from the current directory’s docker file.

Syntax: docker build

Create images from GIT remote repository.

This command is used to create images from the remote repository.

Syntax: docker build github.com/creack/docker-firefox

Tag and building

This command is used to tag and build.

Syntax: docker build -t eon/infinite

Create an image from the docker file

This command is used to create images from a docker file.

Syntax: docker build -f myDockerfile

Create a docker file from a URL

This command is used to create a docker file with a particular URL.

Syntax: curl example.com/remote/Dockerfile | docker build -f –

Delete image

This command is used to delete images.

Syntax: docker image rm nginx

Use SRDIN to load an image.

This command loads an image using a file or the standard input stream.

Syntax: docker image load < ubuntu.tar.gz or docker build -f myOtherDockerfile

Save images to tar

This command saves one or multiple images to a tar archive.

Syntax: docker image save busybox > ubuntu.tar

Show the history of an image

This command shows the history of the image inside the docker.

Syntax: image history

Make an image out of a container

This command is used to take an image out of the container.

Syntax: docker container commit nginx

Image tagging

This command is used to tag an image.

Syntax: docker image tag nginx eon01/nginx

Push images

This command is used to push any images.

Syntax: docker image push eon01/nginx

Docker Networking 

By default, you have two network drivers:

  • bridge networks used within a single host
  • overlay drivers for multi-host communication

You can also create your Driver Plugin in an advanced task.

Overlay network

This command establishes a network distributed among multiple docker daemon hosts. 

Syntax: docker network create -d overlay MyOverlayNetwork

Bridge network

This command is used to connect the same bridge network.

Syntax: docker network create -d bridge MyBridgeNetwork

Delete a network

This command is used to delete an overlay network.

Syntax: docker network rm MyOverlayNetwork

List networks

This command is used to list the overlay networks.

Syntax: docker network ls

Obtain information about the network.

This command is used to obtain information about an overlay network.

Syntax: docker network inspect MyOverlayNetwork

Connect the container to the network.

This command is used to connect the container to the network.

Syntax: docker network connect MyOverlayNetwork nginx

Connect the container to the network when it runs.

This command is used to connect the container to the network when it runs.

Syntax: docker container run -it -d --network=MyOverlayNetwork nginx

Disconnect the container from a network.

This command is used to disconnect the container from the network.

Syntax: docker network disconnect MyOverlayNetwork nginx

Expose ports

This command is used to expose the empty ports.

Syntax: EXPOSE <port_number>

Cleaning docker

This section provides you with useful commands to clean up your container.

Remove a running container.

This command is used to remove a running container.

Syntax: docker container rm nginx

Remove a container and its volume.

This command is used to remove the container and everything inside.

Syntax: docker container rm -v nginx

Remove exited containers

This command is used to remove all exited containers.

Syntax: docker container rm $(docker container ls -a -f status=exited -q)

Remove stopped containers

This command is used to remove all stopped containers.

Syntax: docker container rm `docker container ls -a -q`

Remove a docker image.

This command is used to remove a docker image.

Syntax: docker image rm nginx

Dangle images

This command is used to dangle the images.

Syntax: docker image rm $(docker image ls -f dangling=true -q)

Remove all images

This command is used to remove all the images in the docker.

Syntax: docker image rm $(docker image ls -a -q)

Remove all untagged images.

This command is used to remove all the untagged images.

Syntax: docker image rm -f $(docker image ls | grep "^<none>" | awk "{print $3}")

Stop and remove all containers.

This command Is used to remove all the containers.

Syntax: docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q)

Remove all dangled volumes.

This command is used to remove all the dangling volumes.

Syntax: docker volume rm $(docker volume ls -f dangling=true -q)

Remove all unneeded items

this command is used to remove all the unnecessary items such as containers, images, and networks.

Syntax: docker system prune -f

Clean up everything

This command is used to remove everything in the docker.

Syntax: docker system prune -a

  • Docker is an open-source software platform founded in the summer of 2010.
  • Docker provides developers with everything needed to run the software, such as system tools, code, runtime, and libraries.
  • Docker image is software that contains instructions on creating containers. And it can be found on Docker Hub.

People also read: 

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.

user monovm

Ella Bernhard

2024, Jun, 24

This Docker cheat sheet is incredibly comprehensive and useful! It's great to have all these commands and their explanations in one place, especially for both beginners and experienced developers. Thanks for sharing such a detailed guide. The step-by-step instructions for different platforms and the various Docker commands for managing images and containers make it easy to follow. Definitely bookmarking this for future reference!

user monovm

Prof. Dana Mills

2024, Oct, 24

This comprehensive cheat sheet on Docker is a fantastic resource for anyone looking to streamline their development workflow. Docker's ability to encapsulate everything an application needs into containers makes deployment a breeze, and this guide covers all the essential commands to manage images, containers, and networks efficiently. It's great to have such a well-organized and detailed guide, especially for beginners trying to get a grasp on Docker's full potential. Thanks for sharing this!