Chapter 20Lesson 03~125 minutes

Volumes, Named Volumes, Volume Drivers, Backup/Restore, Sharing, and Persistent Data Patterns: Configuration, Design Choices, and Tradeoffs

Choose deliberately among named volumes, bind mounts, local and remote drivers, sharing models, consistency targets, and Compose ownership boundaries.

TradeoffsComposeRemote storageConsistencyOwnership

Learning objectives

  • Choose between a Docker-managed named volume and a host-coupled bind mount based on ownership, portability, and operational needs.
  • Distinguish built-in local-driver semantics from plugin/remote-driver semantics and prerequisites.
  • Decide whether shared access is safe based on the application and storage system rather than Docker mount success alone.
  • Define application-consistent versus crash-consistent backups and connect them to RPO/RTO evidence.
  • Design Compose volume ownership explicitly: project-managed, externally managed, or shared across projects.
Design rule. “The mount works” is not enough. Select a storage design by answering who owns it, where the bytes live, which writers may access it, how consistency is achieved, how it is backed up, and who is allowed to delete it.

1. Named volume versus bind mount

Choice Named volume Bind mount
Ownership Docker/driver manages the storage object Host path is an explicit dependency
Host coupling Lower for application configuration High; path/permissions/OS semantics matter
Portability Good when driver is available Limited by host path layout and filesystem
Backup boundary Operate through the volume mount/driver Host filesystem tools may be appropriate
Developer UX Simple for persisted service data Convenient for source/config editing
Security boundary Docker-managed object still needs permission design Direct host path exposure can widen host coupling
Best fit Database/app state owned by the containerized service Source trees, deliberate host integration, files managed primarily on host

Chapter 21 will explore bind mounts in depth. For persistent service state that should not depend on a workstation directory layout, named volumes are usually the clearer starting point.

2. Local versus plugin/remote volume drivers

The built-in local driver stores/provisions storage according to the daemon host and local driver options. Volume plugins can integrate external storage and can make data persist beyond one Docker host. That extra capability also adds a trust boundary, credentials, network dependency, performance profile, consistency model, and plugin lifecycle.

Question Local driver Plugin/remote driver
Where are semantics documented? Docker local-volume docs and host filesystem/mount behavior Specific driver/provider documentation
Cross-host mobility Not automatic May be supported by backend/driver
Credentials Usually none for simple local storage Often required; never embed in Compose casually
Failure modes Host disk, permissions, filesystem Plus network/provider/plugin/control-plane failures
Mountpoint meaning Often host/VM path visible to daemon May represent plugin-provided/remote mount implementation
Backup mechanism File/app-level or host snapshot as designed Provider snapshots, app backup, or file-level depending on semantics

Never infer that a remote driver supports POSIX locking, multi-writer, snapshots, encryption, or failover merely because Docker successfully mounted it.

3. One writer versus shared access

Docker can attach the same named volume to multiple containers. That proves mountability, not correctness. Many embedded databases and stateful applications require a single writer or coordinated clustering protocol. Shared writable storage can corrupt data if the application and backend do not support concurrent access.

Use read-only consumers when possible. For multiple writers, document the application-level concurrency contract, storage protocol, locking/consistency behavior, failure recovery, and platform/driver prerequisites.

4. Crash-consistent versus application-consistent backup

Backup type Meaning Suitable evidence
Crash-consistent Files reflect some point close to a sudden power loss Filesystem/snapshot timestamp, checksum, successful application recovery test
Application-consistent Application has flushed/checkpointed/paused or produced a logical backup Application backup logs/checkpoint ID plus archive/snapshot identity and restore test
Continuous/replicated Recovery comes from replicated/streaming state Lag/RPO metrics, replica health, tested promotion/restore procedure

Stopping a simple synthetic writer is enough for this course's file backup. A production PostgreSQL, MySQL, MongoDB, or other database needs its own supported backup/consistency method. Docker does not know the application's transaction boundaries.

5. Project-managed versus external Compose volume

A top-level Compose volume without external: true is normally created and labeled as part of the Compose project. docker compose down preserves such named volumes by default; adding --volumes opts into deleting them. An external volume is expected to exist outside the project's lifecycle and is never removed by down.

# Project-managed volume
services:
  app:
    image: busybox:1.36.1
    volumes:
      - app-data:/data
volumes:
  app-data: {}

# Externally managed volume
# volumes:
#   app-data:
#     external: true
#     name: shared-production-data

Use external ownership when creation/deletion belongs to another lifecycle, team, infrastructure system, or shared environment. Do not use it merely to avoid understanding Compose cleanup behavior.

6. Decision table

Scenario Preferred starting point Prerequisites/evidence Why
Single-host local DB in dev Named volume, local driver Explicit project name; backup/restore lab Low host-path coupling.
Source code live editing Bind mount Known host path and permissions Host owns the source tree.
State shared across hosts Reviewed remote/plugin driver or application-native replication Driver/backend support, auth, failure model, tested recovery Local driver alone does not provide cross-host storage.
Read-only reference dataset Named volume mounted read-only or image artifact depending update model Checksum/version and immutable source Prevents accidental runtime mutation.
Shared production database Usually application/database-native HA + dedicated storage design Vendor support, consistency, fencing/locking, backup/restore Multiple Docker mounts alone are not an HA design.

7. Worked scenario: analytics service with daily imported data

The service runs on one Docker host, imports a 2 GB dataset nightly, and must retain the previous day's recoverable state. A named local volume is reasonable if the host is the accepted failure domain. The operational contract should include a daily application-quiesced archive or host snapshot, checksum, retention policy, restore test, disk-space monitoring, and documented host-backup dependency.

If the requirement changes to “survive host loss with minutes of RPO,” the correct change is not a random volume plugin. Re-evaluate the application/data architecture, remote storage semantics, replication, and recovery objectives together.

8. Design checklist

  • Who creates and deletes the volume?
  • Which driver and exact driver options are required?
  • Which containers may read and which may write?
  • What numeric UID/GID and mode should persisted files have?
  • What is the acceptable RPO and RTO?
  • How is application consistency established before backup?
  • Where is the backup stored relative to the host failure domain?
  • How often is restore tested into a separate target?
  • Which labels/metadata identify owner, environment, and retention?
Next lesson

Next: Volumes, Named Volumes, Volume Drivers, Backup/Restore, Sharing, and Persistent Data Patterns: Diagnostics, Failure Modes, Security, and Performance

Diagnose the storage failures that occur when lifecycle, permissions, consistency, driver behavior, and cleanup intent are conflated.

Knowledge check

Can two containers mounting the same volume write safely just because Docker allows it?

What does external: true mean for a Compose volume?

Why can a remote volume driver change the threat model?

What distinguishes an application-consistent backup?

When is a bind mount usually preferable?

Official references and version notes

Version baseline, verified 2026-09-21.

Docker Engine 29.8.1 is current; Docker Compose 5.5.1, Buildx 0.37.1, and BuildKit 0.33.0 are the current upstream baselines used for compatibility discussion. The mandatory labs use the built-in local volume driver and BusyBox, require no paid service, and record the learner's actual installed versions rather than assuming they match upstream.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.