In this tutorial, you’ll learn how to inspect, remove, prune, and configure Docker volumes. Managing volumes effectively helps persist data across container lifecycles and keeps your host system clean.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Table of Contents
- Inspecting a Volume
- Removing a Volume
- Pruning Unused Volumes
- Verifying Mount Options
- Mounting a Volume as Read-Only
- References
Inspecting a Volume
Usedocker volume inspect to retrieve metadata about your volume, including driver, mount point, labels, and scope:
Removing a Volume
To delete a volume that’s no longer used by any container:Pruning Unused Volumes
Clean up all dangling volumes in one step to free up disk space:Pruning removes all unused volumes. Ensure you have backups of any critical data before proceeding.
Verifying Mount Options
By default, volumes are mounted read-write. To inspect a container’s mount configuration:Mounts section:
The
"RW": true field confirms the volume is mounted read-write inside the container.Mounting a Volume as Read-Only
To ensure data integrity, you can mount a volume as read-only. Use the--mount flag with readonly:
Common Docker Volume Commands
| Command | Description | Example |
|---|---|---|
| docker volume ls | List all volumes | docker volume ls |
| docker volume inspect [NAME] | Show detailed info about a volume | docker volume inspect data_volume |
| docker volume rm [NAME] | Remove a specific volume | docker volume rm data_volume |
| docker volume prune | Remove all unused volumes | docker volume prune |