9 little-known but powerful Docker commands

In the development world, Docker has become an indispensable tool, providing developers with many powerful features and flexibility. From deploying applications to building containerized microservices architectures to enabling continuous integration and continuous delivery, Docker plays an important role in developer workflows.

However, while we may already be familiar with common Docker commands, such as building images, running containers, and viewing logs, there are still some less-known commands that can help developers better utilize the potential of Docker and make work more efficient and convenient. . 

By sharing these commands, developers can learn from each other and explore new ways to handle various Docker tasks, thereby strengthening skills and knowledge.

docker history

The docker history command is used to view the history of Docker images, provide a timeline of the image, and display the creation process and related information of each layer image. This information is valuable for understanding the image’s build process and dependencies between layers, and helps identify areas of potential optimization in Docker images.

docker history yourimage

system df

The docker system df command is used to view disk usage on the Docker host, providing detailed information about disk space, including used space, free space, and file system type. This command can help developers monitor and manage storage resources on the Docker host.

docker system df


The docker container prune command can clean up stopped Docker containers that are no longer in use. It can help free up disk space and resources, remove unused containers and clean up related network and storage resources. This command is a shortcut to clean up the Docker environment and can provide better resource management and performance optimization.

docker container prune

You can also use the prune command to delete an image, but unlike a container, you need to use the image keyword to specify that the operation object is an image rather than a container. like this:

docker image prune


Use this command to enter a running Docker container and interact with the inside of the container. Through the exec command, developers can easily perform various operations in the container, such as running programs, viewing logs, debugging, etc. This is useful for troubleshooting or exploring the internals of a container.

docker exec -it yourcontainer_id bash1.

docker CP

Docker CP command is used to copy files and directories between local host and Docker container. Supports copying files from the host to the container, or from the container to the host, to realize file interaction between the host and the container. 

This command is very convenient and can be used to add files to the container, extract files from the container, or transfer files between the container and the host.

For example, you can use the following example to copy files from a container to the current directory:

docker cp yourcontainer_id:/path/to/container/file /path/to/host/destination

docker events

The docker events command can monitor and display the flow of events related to Docker. It provides real-time, continuously updated event logs, including container creation, starting, stopping, deletion and other operations, as well as image pulling and pushing operations. 

Through the docker events command, developers can easily track and monitor various events that occur in the Docker environment, so as to understand the system status and troubleshoot in a timely manner.

docker events

docker stats

The docker stats command provides real-time statistical information flow on container resource usage, including CPU, memory, network and other information. 

This feature is useful for monitoring and understanding how containers are utilizing resources.

docker stats container_id

“docker save” and “docker load”

This command is an abbreviation for saving a Docker image to a tarball (short for “tape archive”, a file format that combines multiple files into a single archive. It is usually compressed to reduce size.

Tarballs are commonly used for bundling in Unix and Linux environments files and directories and retain their structure) and a convenient tool for loading them back. This process is useful when you need to transfer images between different environments without relying on the registry.

docker save -o myimage.tar yourimage docker load -i myimage.tar

docker network ls

The docker network ls command can list all networks created by Docker. 

This is helpful for checking and viewing the networks that currently exist on the system.

docker network ls

🔥 [20% Off] Linux Foundation Coupon Code for 2024 DevOps & Kubernetes Exam Vouchers (CKAD , CKA and CKS) [RUNNING NOW ]

Save 20% on all the Linux Foundation training and certification programs. This is a limited-time offer for this month. This offer is applicable for CKA, CKAD, CKSKCNALFCS, PCA FINOPSNodeJSCHFA, and all the other certification, training, and BootCamp programs.

[lasso ref=”ckad-exam-2″ id=”3916″]
[lasso ref=”cka-exam-2″ id=”3912″]
[lasso ref=”cks-exam” id=”3592″]

Check our last updated Kubernetes Exam Guides (CKAD , CKA , CKS) :


I hope by y sharing these commands, developers can learn from each other and explore new ways to handle various Docker tasks, thereby strengthening skills and knowledge.

Leave a Reply
You May Also Like