# Container Volume

> Storage that outlives the container. Files kept there stay when the box is gone.

**Field:** Infrastructure  
**Category:** Containers  
**Also known as:** Docker Volume, Volume (Containers)

## Think of it like

It is like a backpack you keep when you change coats. Your things stay safe in it.

## Definition

A container volume is storage that lives outside the container. The container sees it as a normal folder. When the container is deleted, the volume and its files stay. A new container can plug in the same volume and carry on. This is how a database in a container keeps its data.

## Example

Jack runs a database in a container and keeps its data in a volume. He swaps in a newer version. Every record is still there.

## Example code

```console
$ docker volume create notes
notes
$ docker run --rm -v notes:/data alpine sh -c 'echo hi > /data/note.txt'
$ docker run --rm -v notes:/data alpine cat /data/note.txt
hi
```

The first container writes a note and is deleted. The second one still reads the note from the volume.

## Why it matters

Without a volume, the files a container saves vanish with it. That is fine for an app, and a disaster for a database.

## Common mistake

Leaving the volume off a database container. The first time the box is replaced, all the data is lost.

## Three principles

- **Lives outside.** The data sits apart from the container.
- **Outlasts the box.** Deleting the container keeps the files.
- **Can be shared.** Two containers can attach the same volume.

## Related terms

- [Container](https://learn.benibix.com/term/infrastructure/container)
- [Docker Compose](https://learn.benibix.com/term/infrastructure/docker-compose)
- [Docker](https://learn.benibix.com/term/infrastructure/docker)
- [Database](https://learn.benibix.com/term/development/database)
- [Bind Mount](https://learn.benibix.com/term/infrastructure/bind-mount)

## Told apart from

- [Container Volume vs Bind Mount](https://learn.benibix.com/compare/container-volume-vs-bind-mount): People think a bind mount is just another volume, and it is not. A bind mount shows a host folder you chose inside the box. A volume is storage the container tool makes and looks after. Both can use the same -v flag, which is why they get mixed up. Use a bind mount to edit code, and a volume to keep a database's files.

![On the left, an old container drawn with a dashed edge and marked deleted. On the right, a new container. Both are joined by lines to one volume drawn below and outside them, where the files live.](https://learn.benibix.com/diagrams/inf-container-volume.svg)

---

Source: https://learn.benibix.com/term/infrastructure/container-volume
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
