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 Type | Description | Persistence |
|---|---|---|
| Image layers | Read-only layers created during docker build | Permanent (stored in image) |
| Container layer | Writable copy of image layers created when docker run executes | Lost 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 Type | Responsibility | Examples |
|---|---|---|
| Storage driver | Manages read-only image layers and the writable container layer | overlay2 (default on Ubuntu), zfs, vfs, aufs (deprecated), devicemapper (deprecated) |
| Volume driver | Manages persistent data outside the container lifecycle | local (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_volumeInspect the volume storage location:
# On Linux
ls /var/lib/docker/volumes/data_volume/_dataRun a container with a volume mount:
docker run -d -p 3000:3000 \
-v data_volume:/app \
--name todo \
day02-todo-v data_volume:/appmounts the named volumedata_volumeto/appinside the container- Any file written to
/appinside the container is persisted to/var/lib/docker/volumes/data_volume/_dataon 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 runcycles - Multiple containers can mount the same volume (shared persistent storage)
- Docker manages the lifecycle —
docker volume rmis 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-todoOr using -v shorthand:
docker run -d -p 3000:3000 \
-v /home/ubuntu/mydata:/app \
--name todo \
day02-todoVolume vs Bind Mount:
| Aspect | Named Volume | Bind Mount |
|---|---|---|
| Source | Docker-managed (/var/lib/docker/volumes/) | Any existing host directory |
| Management | docker volume create/ls/rm | Host filesystem only |
| Use case | Application data, databases | Development (live code reload), config files |
| Portability | Portable across hosts | Host-path dependent |
| Syntax | -v name:/container/path | -v /host/path:/container/path |
--mount vs -v
Both achieve the same result but with different syntax:
-vis the older, shorter syntax--mountis 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 myimageWhy This Matters for Kubernetes
Docker storage concepts map directly to Kubernetes storage:
| Docker Concept | Kubernetes Equivalent |
|---|---|
| Named Volume | PersistentVolume (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 (
hostPathvolumes) — 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
Related Sources
- CKA Day 2 — How To Dockerize a Project — Dockerfile basics and image building
- CKA Day 3 — Multi-Stage Docker Build — Layer optimization and caching
- CKA Day 6 — Kind Multi-Node Cluster Setup — Using Docker as the node runtime
Creator / Entity
- Tech Tutorials with Piyush — CKA 40-day course creator
Ingested: 2026-07-06