20 Docker Commands You Have to Be Educated About - (r)
-sidebar-toc>
Docker's main command-line interface (CLI) is a powerful set of tools for developers working using containers. Starting with the basic command docker
The CLI can support nearly 60 subcommands -- most of which take a variety of command line arguments to tackle different tasks.
How to Get Your Hands on Docker CLI Docker CLI
We think that even users of Docker Desktop will find themselves entering the CLI after they have mastered at least 20 of the most essential docker
commands.
Docker Commands You Need to Know
We'll discover which Docker commands should you be the most comfortable with.
1. docker system
The Docker System
command assists in examining and control the Docker system. Command-line arguments are supported when carrying out specific management tasks, for example:
df
will show you how to be making use of the diskreduce
eliminates networks that are not used, containers, images, or even volumesinfo
contains information related to the system.events
shows a record of system events, in real-time
Here is the first prompt when you execute docker system pruning
.
2. docker context
This command helps you use different contexts to navigate and modify them. With Docker contexts, you can find names, information about transport layer security info, endpoint configurations, and orchestrators.
Certain are the donker context
arguments
Ls
provides the specifics about the standard contextinspect [CONTEXT|]}
analyzes a specific context- create [CONTEXT create [CONTEXT creates a new context
utilizes [CONTEXT]
toggles between different contexts
Here is an example the output of docker context"ls"
:
3. Docker pause, then remove the pause
The docker pausing
command will freeze a container's active processes. In order to run it you need to specify the container's name, as shown below:
docker pause [CONTAINER]
Below is an example what you might expect to see after pausing an empty container.
The docker unpause
command restarts container processes. Like the previous command, you must specify the name of the container, in the following format:
docker unpause [CONTAINER]
Below is a sample of the output that you could expect after unpausing a container.
4. docker rm
This command removes containers, volumes, and networks. It lets you select which component to be removed by its attributes. In particular, you could take out running containers by force or all specified containers:
docker rm "CONTAINER"
eliminates the container whose name is defined. The result of this command is in the screen capture below.
5. docker 5. rmi
You use this command to delete images. It is possible to remove one image or multiple at once. You can describe the image to remove using either your short ID, or the long ID. This command is crucial to keep the host node in good order and running efficiently.
The command used to remove images uses this structure:
docker RMI [IMAGE ID]
Below is an example the output.
6. docker volume
This command lets you control volumes using Docker. You can use it to add, edit the, check, or list the volume.
A few of the Docker Volume
arguments are:
Create [OPTIONAL NAME[OPTIONAL NAME]
creates a brand new volume. You can specify the volume's name, or allow Docker create a random name.Ls
lists the volumes availableinspect [NAME]
shows detailed volume information.Rm[NAME]
takes a volume out of Docker.
Here is an example of the output after the creation of the volume.
7. Docker search
This command lets you find images available on Docker Hub, which you can then run as containers on your system. This allows you to browse Docker Hub registry images without visiting the website.
The command follows this structure: docker search
. You can specify the names of the images you're looking for, or you can set up an appropriate filter.
Here is an example of the output from the following query:
docker search --filter is official=true mysql
8. Docker push
This docker push
command lets you share your images in Docker Hub. Docker Hub registry or even a private repository.
The command's structure is:
docker Push [OPTIONS] NAME[TAG]
[OPTIONS]
allows you to set -disable-content-trust
.
By default, this value is set, but it's not mandatory to include it.
NAME[:TAG] requires using the registry's name, the repository, and the image tag.
Below is an example of output generated by docker push
.
9. Docker pull
This procedure downloads an Docker image from a registry public or private registry.
The command works like this:
docker pull [OPTIONS] NAME[TAG|@DIGEST[:TAG
This command allows you to use existing images instead of making new ones every time you have to build an application that is containerized.
Below is an example of the output from the docker pull
command:
10. docker 10. docker
This command by default displays the list of all the containers currently running. However, you can set a flag to display containers based on characteristics like disk usage size as well as linked containers and labels.
The command is based on the structure as follows:
docker PS [OPTIONS"
Its arguments can include:
-a
displays a list of the containers that are running as well as those that have been closed.-s
will show each container's physical dimension and size in virtual
You can use the two together like this:
docker as ps
Below is an example the output from an example of the output from a docker command. Below is an example of the output from a ps
command.
11. docker tag
This tag can be used to add metadata, for example the version number, to the image. Tags usually are added when the image is created, but docker tag commands allow you to add tags later. docker tag
command allows you to add a tag later by creating an alias to the intended image.
The command is based on the following structure:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
In the example below the images are listed with the name "redis." After tagging the image with the"version number" ("2.0") and the brand new alias and originally tagged image appear in the listing.
12. docker rename
You can use this command to rename the container. This can be useful if there are multiple containers in your system and you want to distinguish them based on their purpose.
The command is based on the format below:
docker name rename [OLD_NAME][NEW_NAMEName
Here is an example of the output prior to and following the docker rename
command.
13. Docker commit
This command lets you create new images after changes to a container's files. This is important because it enables you to analyze a container by using the interactive Shell.
The command is based on the following format:
docker commit [CONTAINER_ID] [name-of-new-image]
Here is an example of an output from the commit
command.
14. docker network
This is a management of networks command that allows you to create powerful applications by connecting services and containers.
The command follows the following form:
docker network (OPTIONS)
The arguments it offers are based on:
connect
for connecting containers to networkscan be used to build
the basis for new networksdisconnect
for disconnecting running containers from the networksrm
to remove one or more networks
Here is the output of the docker network creation
command.
15. docker history
The command displays the entire history of an image that you have specified, helping you understand how it was created as well as displaying the size of the image.
The command has the following form:
docker history [IMAGE Docker History [IMAGE
Below, we see the past history of the photo redis:latest
.
16. docker update
This command allows you to change the configuration of your container. This helps to prevent containers from taking up too much Docker host resources. The command's format is:
docker update [OPTIONS] [CONTAINER]
Some of its options include:
--restart
refreshes a container's restart policy--memory
defines a container's memory limit--cpus
determines the amount of CPUs that are allocated.
Here is an example the output of a docker update
command.
17. docker plugin install
This command allows you to control plugins. This is important because it lets you add new features without modifying Docker host configurations.
The docker plugin
arguments include:
Create
the possibility of creating plugins with new features.activate
for enabling plug-insinstall
for installing new pluginsrm
for removing one or more pluginsls
for displaying a listing of plugins
Below, we will use docker plugin install
to install the plugin into our environment. We then use docker plugin to display its status.
to display its condition.
18. Container for docker
This command lets you manage containers. You use it to perform actions such as creating or killing containers, among others.
The containers for docker
choices are:
Create
the containercommit
to generate a new image after changes to a containerexecutable
to execute commands within the running containerkill
for stopping a running containerls
for showing an inventory of the containers that are part of a Docker hostrestart
for restarting a containerrun
is a method of creating the container of an image and then running itrm
to remove the container from a Docker host
Below is an example of the output generated by an Docker container
command.
19. docker logs
This command retrieves logs from the container. It provides insights into the container's activities, which may be essential when trying to debug.
Below is an example of the output of an docker logs
command.
20. docker swarm
This command helps manage a Docker Swarm, which is a group of machines (virtual or physically) that are running Docker and designed to function as an organized cluster. This command is easy to set up a swarm and take advantage of its advantages.
Below are a few docker Swarm
options:
an init
to start the swarmjoin
to join an swarmleave
for leaving a swarmupdate
for updating an cluster
Below is an example as well as an output from a docker swarm initialization
command.
Summary
Docker is a powerful instrument for creating and implementing containers-based applications. Its simple-to-understand commands in its CLI make creating and manipulating even complex applications easier.
Mastering the 20 commands above can speed up the development of your containerized application.
Steve Bonisteel
Steve Bonisteel is a Technical Editor for the site. He began his career in writing as a newspaper reporter, who was chasing ambulances and fire engines. The journalist has covered internet-related technologies since the mid 1990s.