Day 28/40 — Docker Volume Explained: Docker Bind Mount & Docker Persistent Storage

Overview

Day 28 of the 40-day CKA course explains Docker storage fundamentals — a prerequisite for understanding Kubernetes storage (PersistentVolumes, PVCs, and StorageClasses) in the upcoming videos. The video covers Docker’s layered architecture, storage drivers, volume drivers, how to create persistent storage with Docker volumes, and the difference between volumes and bind mounts.

Key Concepts

Docker Layered Architecture

A Docker image is built from a series of read-only layers, where each instruction in the Dockerfile creates one layer:

FROM node:18-alpine      → Layer 1 (base image)
WORKDIR /app             → Layer 2
COPY . .                 → Layer 3
RUN yarn install         → Layer 4
EXPOSE 3000              → No layer (metadata)
CMD ["node", "server.js"] → No layer (runtime command)

Benefits of layered architecture:

  • Build cache: Only changed layers are rebuilt. If you modify one instruction, layers before it are reused from cache.
  • Immutable infrastructure: The same image deployed in dev is promoted to staging/prod without modification.
  • Deduplication: Common base layers are shared across images.

Read-Only vs Writable Layers

Layer TypeDescriptionPersistence
Image layersRead-only layers created during docker buildPermanent (stored in image)
Container layerWritable copy of image layers created when docker run executesLost when container is removed

When you docker exec into a running container and create files, those changes live in the container layer — a writable overlay on top of the read-only image layers. Once the container is stopped and removed, this data disappears.

Storage Drivers vs Volume Drivers

Driver TypeResponsibilityExamples
Storage driverManages read-only image layers and the writable container layeroverlay2 (default on Ubuntu), zfs, vfs, aufs (deprecated), devicemapper (deprecated)
Volume driverManages persistent data outside the container lifecyclelocal (default), ebs (AWS), gce (GCP), azure_file, vsphere, portworx

Docker automatically selects the best storage driver for your OS. overlay2 is the modern default for most Linux distributions.

Docker Volumes

A Docker volume is a named, managed storage area managed by Docker’s volume driver. It persists data on the host filesystem at /var/lib/docker/volumes/, outside the container’s union filesystem.

Create a volume:

docker volume create data_volume

Inspect the volume storage location:

# On Linux
ls /var/lib/docker/volumes/data_volume/_data

Run a container with a volume mount:

docker run -d -p 3000:3000 \
  -v data_volume:/app \
  --name todo \
  day02-todo
  • -v data_volume:/app mounts the named volume data_volume to /app inside the container
  • Any file written to /app inside the container is persisted to /var/lib/docker/volumes/data_volume/_data on the host
  • If the container is stopped, removed, and recreated with the same volume mount, the data remains

Key behaviors:

  • Data survives container stop/start and even docker rm + docker run cycles
  • Multiple containers can mount the same volume (shared persistent storage)
  • Docker manages the lifecycle — docker volume rm is required to delete the data

Bind Mounts

A bind mount mounts an existing host directory into a container, bypassing Docker’s volume management entirely.

Run with bind mount:

docker run -d -p 3000:3000 \
  --mount type=bind,source=/home/ubuntu/mydata,target=/app \
  --name todo \
  day02-todo

Or using -v shorthand:

docker run -d -p 3000:3000 \
  -v /home/ubuntu/mydata:/app \
  --name todo \
  day02-todo

Volume vs Bind Mount:

AspectNamed VolumeBind Mount
SourceDocker-managed (/var/lib/docker/volumes/)Any existing host directory
Managementdocker volume create/ls/rmHost filesystem only
Use caseApplication data, databasesDevelopment (live code reload), config files
PortabilityPortable across hostsHost-path dependent
Syntax-v name:/container/path-v /host/path:/container/path

--mount vs -v

Both achieve the same result but with different syntax:

  • -v is the older, shorter syntax
  • --mount is the newer, more explicit syntax with comma-separated key-value pairs
# Equivalent commands
docker run -v data_volume:/app myimage
docker run --mount type=volume,source=data_volume,target=/app myimage
 
docker run -v /host/path:/container/path myimage
docker run --mount type=bind,source=/host/path,target=/container/path myimage

Why This Matters for Kubernetes

Docker storage concepts map directly to Kubernetes storage:

Docker ConceptKubernetes Equivalent
Named VolumePersistentVolume (PV) — cluster-wide storage resource
Volume driver (local, ebs, gce)StorageClass — defines the provisioner and parameters
Volume creation (docker volume create)PersistentVolumeClaim (PVC) — requests storage from a PV/StorageClass
Bind mount (-v /host:/container)hostPath volume — mounts a host directory into a Pod
Container layer (non-persistent)emptyDir volume — ephemeral Pod-scoped storage

Understanding Docker volumes and bind mounts makes Kubernetes PersistentVolumes, PVCs, and StorageClasses much easier to grasp.

CKA Exam Relevance

  • Docker storage is a prerequisite, not a direct CKA exam topic. The exam tests Kubernetes storage (PVs, PVCs, StorageClasses).
  • However, understanding Docker’s layered architecture helps debug image build issues and container filesystem behavior.
  • The exam may present scenarios where you need to mount host paths into Pods (hostPath volumes) — the bind mount concept applies.

See Also

Wiki Concepts

  • Docker Storage — Deep-dive into layered architecture, storage drivers, volume drivers, volumes, bind mounts, and the Kubernetes storage bridge
  • Docker Fundamentals — Container architecture, images, and the Docker workflow
  • Dockerize a Project — Writing Dockerfiles, multi-stage builds, and layer caching
  • Kubernetes Concepts Index — Storage section: Volumes, PersistentVolumes, PVCs, StorageClasses

Creator / Entity


Ingested: 2026-07-06