Module 9 Lesson 3: Inspecting and Managing Volumes
·DevOps

Module 9 Lesson 3: Inspecting and Managing Volumes

Master the administrative side of storage. Learn how to locate your data on the host machine, audit usage, and clean up abandoned storage volumes.

Module 9 Lesson 3: Inspecting and Managing Volumes

If Docker manages your volumes, where are they actually located? And how do you know how much space they are taking up? This lesson provides the admin tools for the storage layer.

1. Finding Your Data (docker volume inspect)

To see the details of a volume, use the inspect command.

docker volume inspect my-db-data

Key Fields in the JSON output:

  • Mountpoint: This is the actual path on your computer where the files live.
    • On Linux: Usually /var/lib/docker/volumes/name/_data.
    • On Mac/Windows: It's inside a hidden Virtual Machine, so you cannot browse it directly from your file explorer easily.

2. Global Cleanup (prune)

Abandoned volumes are the #1 cause of "Disk Full" errors in Docker.

  • docker volume prune: Deletes every volume that is not currently connected to at least one running (or stopped) container.

The "Strict" Cleanup: If you want to remove a container AND its associated volumes in one command:

  • docker rm -v <container_name>

3. Auditing Size

Docker doesn't have a direct docker volume size command. To see how much space a volume is taking, you have to use standard Linux tools from inside a container.

docker run --rm -v my-data:/data alpine du -sh /data
  • du -sh: "Disk Usage - Summary Human-readable".
  • This "Helper Container" patterns is very common for volume administration.

4. Troubleshooting "Dead" Volumes

Sometimes you try to delete a volume and get an error: "volume is in use".

  • Reason: Even if a container is "Stopped," it still holds a lock on its volumes.
  • The Fix: You must delete the Container first (docker rm), then you can delete the volume.

Exercise: The Storage Audit

  1. Run docker volume create audit-test.
  2. Inspect it. Copy the Mountpoint path to a text file.
  3. Run a container that attaches to it and creates a 10MB file.
    • docker run -v audit-test:/test alpine dd if=/dev/zero of=/test/file.dat bs=1M count=10
  4. Now, use the "Helper Container" method from Section 3 to verify the size is 10MB.
  5. Try to delete the volume using docker volume rm audit-test. What happens if the container is still running? What about if it's just stopped?
  6. Finally, use docker system prune --volumes to do a complete cleanup.

Summary

Volume management is a critical skill for keeping your development and production environments healthy. By mastering inspect, prune, and the "Helper Container" pattern, you ensure that you are always in control of where your data is and how much space it uses.

Next Lesson: Moving to the cloud: Volume plugins and cloud storage.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn