30 hidden docker commands you should know and their use cases
Docker offers a wide range of commands to manage containers, images, volumes, networks, and more. While some commands are commonly used, here are a few lesser-known or less frequently used Docker commands:
1. docker system prune
This command helps in cleaning up unused data like stopped containers, unused volumes, and networks. It's a great way to free up disk space.
Caution: It removes all stopped containers, dangling images, and unused networks and volumes.
2. docker stats
Shows live resource usage statistics of running containers.
It displays CPU, memory, network I/O usage, etc., for each container.
3. docker history
Displays the history of an image including the layers and commands used to create it.
Helpful for understanding how an image was constructed and the changes made at each layer.
4. docker export
and docker import
docker export
exports a container's filesystem as a tar archive to stdout.docker import
imports the contents from a tarball to create a filesystem image.
5. docker commit
Creates a new image from changes made to a container.
This can be useful for creating custom images from modified container states.
6. docker network ls --format
Lists networks with custom formatting using Go templates.
Allows customization of the output format according to specific requirements.
7. docker secret
- Manages Docker secrets used for securely storing sensitive data like passwords, tokens, etc., in a Swarm cluster.
8. docker manifest
Handles image manifests, useful for multi-architecture images.
Helps manage images across different architectures and platforms.
9. docker checkpoint
Allows the creation of checkpoints for a running container (requires experimental features enabled).
It's useful for creating backups or restoring container states.
10. docker events
Shows real-time events generated by the Docker daemon.
Useful for monitoring container-related activities.
11. docker diff
Displays the changes made to the filesystem of a container since it was started.
Useful for understanding modifications made within a running container.
12. docker attach
Attaches the terminal to a running container, allowing you to interact with its process stdin, stdout, and stderr.
Similar to
docker exec
,docker attach
connects to the main process in the container.
13. docker cp
Copies files or folders between a container and the local filesystem.
Helpful for moving data in and out of running containers.
14. docker save
and docker load
docker save
saves one or more images to a tar archive, allowing for image backup or sharing.docker load
loads an image or repository from a tar archive.
15. docker logs
Displays logs from a running container.
Useful for troubleshooting and monitoring container output.
16. docker export
vs docker save
docker export
exports the container's filesystem as a tar archive, excluding metadata like image layers or history.docker save
saves the image and its layers as a tar archive, preserving the image's history and metadata.
17. docker top
Displays the running processes of a container.
Similar to the
top
command in Linux, it shows the processes running within the container.
18. docker history --human
Displays the image history with human-readable sizes.
It helps in understanding the sizes of each layer in a more understandable format.
19. docker stats --no-stream
Provides container resource usage statistics once rather than continuously.
Useful when you only need a single snapshot of the container's resource usage.
20. docker manifest inspect
Inspects the image manifest to see the supported platforms for a multi-platform image.
Helps in understanding the architectural support for a particular image.
21. docker history --no-trunc
Displays the full command for each image layer without truncating the output.
Useful for seeing the complete commands executed in each layer during image creation.
22. docker events --filter
Allows filtering Docker events based on various criteria such as container ID, image name, event type, etc.
Useful for monitoring specific Docker events of interest.
23. docker secret inspect
Provides details about a specific Docker secret, including its metadata.
Helpful for checking specific information about a secret stored in Docker.
24. docker plugin
Manages Docker plugins that extend Docker's functionality.
Plugins can add new commands, volumes, networks, or other features to Docker.
25. docker system df
Displays disk usage related to Docker resources.
Provides a summary of the space used by different types of Docker objects like images, containers, volumes, etc.
26. docker manifest create
Creates an empty manifest list for defining multi-platform images.
Useful when building custom multi-architecture image manifests.
27. docker container diff
Shows the changes to the filesystem of a container file system.
Similar to
docker diff
, but specifically for examining the changes made within a running container.
28. docker image import
and docker image export
docker image import
import a tarball to create a filesystem image.docker image export
exports a container's filesystem as a tar archive to stdout.Similar to
docker import
anddocker export
, but specifically for images.
29. docker network inspect
Provides detailed information about a Docker network, including its configuration and connected containers.
Helpful for troubleshooting network-related issues or understanding network configurations.
30. docker run --ulimit
Allows setting ulimit options for a container's resources like memory, CPU, file descriptors, etc.
Useful for limiting resource usage within a container.
Keep in mind that Docker evolves, and some commands or functionalities might be specific to certain Docker versions or might have undergone changes over time. Always refer to the official Docker documentation or use docker --help
for the most up-to-date and accurate information about Docker commands and their usage.
Subscribe to my newsletter
Read articles from Bhanu Bandi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by