Docker enables developers to construct and deploy applications that are neatly tucked away in containers. It provides solutions to issues of OS compatibility by offering lightweight virtual environments for easy application control.
The primary command-line interface (CLI) of Docker equips developers working with containers with potent tools. Stemming from the fundamental command docker
, the CLI has roughly 60 subcommands that accept a range of command-line arguments for different operations.
Mastering Docker CLI Commands
Your specific flavor of Docker could be the open-source Docker Engine or the Docker Desktop featuring a user-friendly GUI interface. While the CLI is critical for interacting with Docker Engine, accessing the command line tool also comes with installing Docker Desktop.
It’s plausible to speculate Docker Desktop users might also find themselves migrating to the CLI when they familiarize themselves with at least the 20 indispensable docker
commands.
Important Docker Commands
Let’s dig into the Docker commands you should be most acquainted with.
1. docker system
The docker system
command offers a way to examine and control the Docker environment. It also provides command-line arguments for different management associated tasks, such as:
df
: Shows how disk space is being utilizedprune
: Removes unneeded networks, containers, images, or volumesinfo
: Provides system-related informationevents
: Displays real-time system events
Brief output after the execution of docker system prune
shown below:
docker system prune
output.2. docker context
This command assists in navigating and configuring various contexts. Docker contexts include identifiers, transport layer security information, endpoint configurations, and orchestrators.
A few of the docker context
command arguments include:
ls
: Displays the details of the default contextinspect [CONTEXT}
: Inspects the specified contextcreate [CONTEXT]
: Creates a new contextuse [CONTEXT]
: Switches between contexts
Here’s an example output of docker context ls
:
docker context ls
output.3. docker pause and unpause
The docker pause
command briefly suspends a container’s active operations. The specified container’s name must be included to execute it, as indicated below:
docker pause [CONTAINER]
An example of expected output after pausing a container is displayed below.
docker pause
output.The command docker unpause
facilitates the resumption of suspended processes in a container. Similar to the preceding command, the container name must be indicated, as shown below:
docker unpause [CONTAINER]
An example of expected output after resuming a paused container is displayed below.
docker unpause
output.4. docker rm
The docker rm
command facilitates the removal of containers, volumes, and networks. It allows the selection of the component to dispose of based on specific attributes. For instance, you can force the removal of running containers or all linked containers.
The docker rm [CONTAINER]
command eliminates the container specified. An output of this command is displayed in the screenshot below.