Skip to content
Guest
Learn Docker · Course Syllabus Show lessons
Networking & Persistence · 8 min read · Intermediate

Volumes & Persistent Data

Keep database files safe across container restarts and upgrades using named Docker volumes and bind mounts.

What you'll learn

  • Understand why a container's writable layer is ephemeral
  • Persist PostgreSQL/SQLite data with named volumes (-v pgdata:/var/lib/postgresql/data)
  • Use bind mounts (-v $(pwd):/app) for live local development

Containers are ephemeral: when you remove a container (docker rm), any files written inside its container layer disappear. To persist database tables or uploaded files safely across container rebuilds, mount a named Docker volume.

Fill-in-the-Blank Exercise

Attach a Named Volume

Mount the named volume dp_data to /var/lib/devpath inside the container.

docker run -d  dp_data: devpath-api

Live Volume Command Lab

Bashvolumes.sh
Expected OutputClick “Run Live” to compile with GNU Bash
# Create & inspect a named volume
docker volume create dp_data
docker run -d -v dp_data:/var/lib/devpath --name api devpath-api

Check Your Understanding

Score: 0 / 1

1. What happens to data stored in a named Docker volume when you run docker rm -f db_container?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind