Docker Cheat Sheet
Docker Cheat Sheet
Docker Architecture
Docker architecture consists of five main components: server, client,
container, image, and registry.
Docker Server
A Docker server or Docker daemon is a program that runs in the
background of your computer and manages Docker containers and
images. When you use the Docker command line interface.
(CLI) to create, run, or manage containers, you interact with the Docker
daemon.
The Docker daemon is an essential platform component that ensures
containers can be started and stopped automatically when the system
boots up.
Docker Client
The Docker client lets users interact with the Docker daemon with its
command-line interface (CLI). In simple terms, it’s the main part of the
Docker architecture for creating, managing, and running container
applications.
When you use the Docker CLI to pass a command, the Docker client
sends the command to the Docker daemon running on your computer,
which then carries out the requested operation. The Docker client can
be installed on any machine that needs to interact with the Docker
daemon, including your local machine, a remote server, or a virtual
server.
Docker Container
A Docker container is a package that contains all the required
prerequisites to run an application.
Containers are designed to be highly portable, meaning that they can be
easily moved from one environment to another, such as from a
developer’s laptop to a testing environment or from a testing
environment to a production environment.
Docker Image
A Docker image is a preconfigured template that specifies what should
be included in a Docker container. Usually, images are downloaded from
websites like Docker Hub. However, it’s also possible to create a
custom image with the help of Dockerfile.
Docker Registry
The Docker registry is a central repository that stores and manages
Docker images. It is a server-based system that lets users store and
share Docker images with others, making it easy to distribute and
deploy applications. The most notable Docker registry is Docker Hub.
Build Commands
Docker uses the build command for building images from a Docker file.
Some of the most common commands include:
Command Explanation
docker build -t imagename/tag Builds and tags an image for easier tracking
Clean Up Commands
To keep your system clean and save disk space, it’s a great idea to
clean up unused images, containers, and volumes. Check the
commands below for more details:
Command Explanation
docker image prune -a Clears all images that are not being used by containers
Removes all stopped containers, all networks not used by
docker system prune
containers, all dangling images, and all build cache
docker diff container Inspects changes to directories and files in the container filesystem
Run Commands
Docker uses the run command to create containers from provided
images. The default syntax for this command looks like this:
docker run (options) image (command) (arg...)
After the default syntax, use one of the following flags:
Flag Explanation
Registry Commands
If you need to interact with Docker Hub, use the following commands:
Command Explanation
docker search term Searches Docker Hub for images with the specified term
Service Commands
Manage all Docker services with these basic commands:
Command Explanation
Network Commands
If you need to interact with the Docker network, use one of the following
commands:
Command Explanation
Suggested Readings
Check out our other Docker tutorials
How to Install Docker on Ubuntu
How to Remove All Docker Images
How to Install WordPress on Docker
How to Create a Docker Container
Conclusion
Docker is a great tool for anyone willing to try out containers. The
learning curve can be steep if you’re unfamiliar with container-based
development. Luckily, having a cheat sheet at hand can speed up the
process, as all common commands are easily reachable, and you don’t
need to look them up on the internet.
In this tutorial, we’ve covered the basics of Docker architecture and
gone through all the basic Docker commands, all of which can be found
in our downloadable Docker cheat sheet.
We hope that you found this Docker tutorial useful. If you have any
questions, leave them in the comments section below.