> ## 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.

# Docker Volume

> Learn to inspect, remove, prune, and configure Docker volumes for effective data persistence and host system cleanliness.

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.

## Table of Contents

* [Inspecting a Volume](#inspecting-a-volume)
* [Removing a Volume](#removing-a-volume)
* [Pruning Unused Volumes](#pruning-unused-volumes)
* [Verifying Mount Options](#verifying-mount-options)
* [Mounting a Volume as Read-Only](#mounting-a-volume-as-read-only)
* [References](#references)

***

## Inspecting a Volume

Use `docker volume inspect` to retrieve metadata about your volume, including driver, mount point, labels, and scope:

```bash theme={null}
docker volume inspect data_volume
```

Sample output:

```json theme={null}
[
  {
    "CreatedAt": "2020-01-20T19:52:34Z",
    "Driver": "local",
    "Labels": {},
    "Mountpoint": "/var/lib/docker/volumes/data_volume/_data",
    "Name": "data_volume",
    "Options": {},
    "Scope": "local"
  }
]
```

This command is essential for troubleshooting mount permissions and verifying where Docker stores your volume data on the host.

***

## Removing a Volume

To delete a volume that’s no longer used by any container:

```bash theme={null}
docker volume rm data_volume
```

If the volume is active, Docker returns an error:

```bash theme={null}
Error response from daemon: remove data_volume: volume is in use - [2be4d9182296…]
```

Stop or remove the container first, then run the same command again:

```bash theme={null}
docker volume rm data_volume
# data_volume
```

***

## Pruning Unused Volumes

Clean up all dangling volumes in one step to free up disk space:

```bash theme={null}
docker volume prune
```

You'll see a confirmation prompt:

```bash theme={null}
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
  data_vol3
  data_vol1
  data_vol2
Total reclaimed space: 12MB
```

<Callout icon="triangle-alert" color="#FF6B6B">
  Pruning removes **all** unused volumes. Ensure you have backups of any critical data before proceeding.
</Callout>

***

## Verifying Mount Options

By default, volumes are mounted read-write. To inspect a container’s mount configuration:

```bash theme={null}
docker container inspect my-container
```

Look for the `Mounts` section:

```json theme={null}
"Mounts": [
  {
    "Type": "volume",
    "Name": "data_vol1",
    "Source": "/var/lib/docker/volumes/data_vol1/_data",
    "Destination": "/var/www/html/index.html",
    "Driver": "local",
    "Mode": "z",
    "RW": true,
    "Propagation": ""
  }
]
```

<Callout icon="lightbulb" color="#1CB2FE">
  The `"RW": true` field confirms the volume is mounted read-write inside the container.
</Callout>

***

## Mounting a Volume as Read-Only

To ensure data integrity, you can mount a volume as read-only. Use the `--mount` flag with `readonly`:

```bash theme={null}
docker container run \
  --mount type=volume,source=data_vol1,target=/var/www/html,index.html,readonly \
  httpd
```

This is useful for scenarios where containers should not modify shared data.

***

## 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`               |

***

## References

* [Docker Volumes Overview](https://docs.docker.com/storage/volumes/)
* [Use Bind Mounts or Volumes](https://docs.docker.com/storage/bind-mounts-vs-volumes/)
* [Docker CLI Reference](https://docs.docker.com/engine/reference/commandline/volume/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/docker-certified-associate-exam-course/module/44e269a4-bbba-4b6a-9540-696a6f90bace/lesson/05b25198-16e2-48c7-bf27-57fcff207044" />
</CardGroup>
