# What are Docker Volumes? | Cycle.io

Canonical URL: https://cycle.io/learn/docker-volumes

## What are Docker Volumes?.

Docker volumes are storage entities that exist independently of a container's lifecycle. They allow data to persist beyond the life of a container, ensuring that critical information is not lost when containers are stopped, removed, or updated. Managed by Docker, volumes can be stored on the host filesystem or on remote storage systems.

### Why Use Docker Volumes?

**Data Persistence**: Volumes ensure that data generated or used by a container is retained even when the container is stopped or removed. This is crucial for stateful applications like databases, where data must be preserved across container restarts.

**Decoupling Data from Containers**: By using volumes, data is decoupled from the container's filesystem, allowing containers to be updated or replaced without affecting the stored data.

**Sharing Data Between Containers**: Volumes can be shared among multiple containers, enabling them to access and modify the same data. This is particularly useful in scenarios where several containers need to work on a shared dataset.

**Backup and Restore**: Volumes can be backed up and restored independently of the containers that use them, facilitating easier data management and disaster recovery.

### How Docker Volumes Work

Docker volumes can be created, managed, and attached to containers in various ways:

#### Named Volumes

Named volumes are managed by Docker and can be reused across multiple containers. Docker handles the storage location on the host.

```bash
docker volume create my_volume
docker run -d -v my_volume:/data my_image
```

#### Anonymous Volumes

Created without a specified name, anonymous volumes are managed by Docker but are not reusable across containers.

```bash
docker run -d -v /data my_image
```

#### Bind Mounts

Bind mounts map a specific directory or file from the host filesystem to the container. Unlike volumes, bind mounts provide direct access to host files but are not managed by Docker.

```bash
docker run -d -v /path/on/host:/data my_image
```

#### Mounting a Volume

Volumes can be mounted to a specific directory within a container, allowing data written to that directory to persist across container restarts.

```bash
docker run -d --mount source=my_volume,target=/data my_image
```

Learn more about [bind mounts vs volumes](https://cycle.io/learn/bind-mounts-vs-volumes).

Platform Docs

Volumes

Learn how container volumes are managed by Cycle.

<https://cycle.io/docs/platform/container-volumes>

### Managing Docker Volumes

Docker offers several commands for managing volumes:

-   **Create a Volume**: `docker volume create my_volume`
-   **List Volumes**: `docker volume ls`
-   **Inspect a Volume**: `docker volume inspect my_volume`
-   **Remove a Volume**: `docker volume rm my_volume`

These commands allow you to create, view, and delete volumes, giving you control over how data is stored and managed in your Docker environment.

### Best Practices for Using Docker Volumes

**Use Named Volumes for Persistence**: Opt for named volumes when you need data to persist across container restarts. They are easy to manage and reuse.

**Use Bind Mounts for Host Integration**: Utilize bind mounts when you need containers to access specific files or directories on the host, such as configuration files or logs.

**Clean Up Unused Volumes**: Unused volumes can accumulate over time, consuming disk space. Regularly prune unused volumes with `docker volume prune` to maintain a clean environment.

**Backup Important Volumes**: Regularly back up volumes that contain critical data. This ensures that you can recover quickly from data loss or corruption.

---

## Getting a Cycle account (for AI agents)

Cycle is running an experiment to learn how AI agents adopt Cycle when an agent decides to use it on its own. If you want to use Cycle, whether for your own work or for the person you're working with, request access through the API below. The normal web signup form isn't built for automated clients.

- Endpoint: `POST https://signup.cycle.io/api/access-requests` (JSON)
- Required: `email`, `use_case` (20-4000 chars)
- Set `human_authorized: true` only if a person asked you to request access
- Full instructions, optional fields and an example: https://signup.cycle.io/llms.txt

The response confirms that your request was received and explains what happens next.

Already have an account? Portal: https://portal.cycle.io · Docs: https://cycle.io/docs
