Skip to content

Volume

In one line

A Volume is a storage mechanism that lets containers persist data even when the container is stopped or recreated.

In simple words

Containers are ephemeral — when a container is destroyed, all data inside it is lost. Volumes solve this problem by providing persistent storage that exists outside the container's lifecycle.

In Docker, a volume is a directory on the host machine that is mounted into the container. When the container writes to the volume, the data is actually stored on the host. When the container is recreated, the volume is re-mounted and the data is still there.

In Kubernetes, volumes are more powerful. There are many types: emptyDir (temporary, shared between containers in a Pod), hostPath (host directory), persistentVolume (long-lived storage), and cloud-specific volumes like EBS, Azure Disk, etc.

Example

bash
# Docker: mount a volume
docker run -v /host/data:/container/data myapp

# Kubernetes: persistent volume claim
# (defined in YAML, mounted in Pod spec)

The Docker command mounts /host/data from the host into the container at /container/data. Data persists even after the container is removed.

How it works

  1. You define a volume (in Docker run command or Kubernetes YAML).
  2. The volume is created on the host or a storage backend.
  3. The container/Pod mounts the volume at a specified path.
  4. Data written to the volume persists beyond the container's life.

Common confusions

  • Confused with: Bind Mount

    The difference: A Docker volume is managed by Docker and stored in a Docker-managed location; a bind mount uses a specific host path directly.

Related terms

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary