20 Docker Commands You Have to Be Educated About - (r)

Dec 14, 2023
An illustration representing Docker commands.

-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 disk
  • reduce eliminates networks that are not used, containers, images, or even volumes
  • info 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.

Screenshot: the docker system prune command.
docker system prune output.

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 context
  • inspect [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":

Screenshot: the docker context command.
docker context output. output.

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.

Screenshot: the docker pause command.
docker to pause output.

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.

Screenshot: the docker unpause command.
docker unpause output.

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.

Screenshot: the docker rm command.
docker rm output.

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.

Screenshot: the docker rmi command.
docker rmi 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 available
  • inspect [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.

Screenshot: the docker volume create command.
docker volume create output.

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
Screenshot: the docker search command.
docker searching output.

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.

Screenshot: the docker push command.
docker push output.

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:

Screenshot: the docker pull command.
Docker Pull output.

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.

Screenshot: the docker process status command.
A portion of the output from the docker output of the 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.

Screenshot: the docker tag command.
Docker Tag output.

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.

Screenshot: the docker rename command.
docker rename output.

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.

Screenshot: the docker commit command.
commit docker output.

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 networks
  • can be used to build the basis for new networks
  • disconnect for disconnecting running containers from the networks
  • rm to remove one or more networks

Here is the output of the docker network creation command.

Screenshot: the docker create command.
docker network produces output.

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.

Screenshot: the docker history command.
Docker History of output.

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.

Screenshot: the docker update command.
docker update output.

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-ins
  • install for installing new plugins
  • rm for removing one or more plugins
  • ls 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.

Screenshot: the docker plugin command.
docker plugin ls output.

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 container
  • commit to generate a new image after changes to a container
  • executable to execute commands within the running container
  • kill for stopping a running container
  • ls for showing an inventory of the containers that are part of a Docker host
  • restart for restarting a container
  • run is a method of creating the container of an image and then running it
  • rm to remove the container from a Docker host

Below is an example of the output generated by an Docker container command.

Screenshot: the docker container command.
restart of the container for docker output.

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.

example-docker-command-logs
docker logs output.

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 swarm
  • join to join an swarm
  • leave for leaving a swarm
  • update for updating an cluster

Below is an example as well as an output from a docker swarm initialization command.

example-docker-command-swarm-init
docker swarm init output.

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.