Docker & Containers

Volumes & Persistence

Keep data alive beyond the container lifecycle.

25 min read beginner 3 objectives

Status

Not started

What you will learn

  • Use named volumes
  • Mount bind mounts
  • Understand data persistence

New to this? Start here

The basics, in plain English

Containers are throwaway by design: delete one and its internal data is gone. A volume is a separate storage area that lives outside the container, so important data like a database survives restarts.

Ephemeral
Short-lived. A container’s own files vanish when it is removed.
Volume
Storage managed by Docker that persists even after a container is deleted.
Persistence
Keeping data alive beyond the life of any single container.
Bind mount
Linking a folder on your computer into the container, handy during development.
Why it matters
Without volumes, restarting a database container would wipe all its data.
01

Stateless by default

Containers are ephemeral. Volumes persist data outside the container layer; bind mounts map host paths in for development.

Try it yourself

bash
$docker volume create pgdata
Create a named volume that survives container restarts.
$docker run -v pgdata:/var/lib/postgresql/data postgres
Mount the volume so Postgres data persists outside the container.
↳ lines explain what each command does — only the commands get copied

Finished this topic?

Mark it done to earn 100 XP and keep your streak alive.