Docker Docker VolumesPersistent Storage

Article & Tutorial

Docker Volumes Explained: Named Volumes, Bind Mounts and Persistent Data

Understand named volumes, bind mounts, container persistence, database storage, backups, permissions, common mistakes, and reliable data-management patterns.

Docker volumes and persistent container storage
Docker volumes and persistent container storage
Contents

Docker Volumes Explained

Containers are temporary by design. Docker volumes help you persist important data even when containers are stopped, removed, recreated, or upgraded.

Quick answer

Named volume

Managed by Docker and usually stored under Docker’s data directory.

Bind mount

Maps a specific host folder or file into a container.

tmpfs mount

Stores temporary data in memory and disappears after container stops.

Why volumes matter

If you run a database container without a volume, important data can be lost when the container is removed. Volumes separate data from the container lifecycle.

Named volume example

docker volume create mysql_data docker run -d --name mysql \ -e MYSQL_ROOT_PASSWORD=mysecret \ -v mysql_data:/var/lib/mysql \ mysql:8

Bind mount example

docker run -d --name web \ -p 8080:80 \ -v $(pwd)/html:/usr/share/nginx/html \ nginx

Bind mounts are useful during development because local file changes can reflect inside the container.

Volume commands

docker volume ls docker volume inspect mysql_data docker volume rm mysql_data docker volume prune

Backup a named volume

docker run --rm \ -v mysql_data:/data \ -v $(pwd):/backup \ alpine tar czf /backup/mysql_data_backup.tar.gz -C /data .

Restore a named volume

docker run --rm \ -v mysql_data:/data \ -v $(pwd):/backup \ alpine sh -c "cd /data && tar xzf /backup/mysql_data_backup.tar.gz"

Common mistakes

  • Running databases without volumes.
  • Deleting volumes during cleanup without checking data.
  • Using bind mounts in production without proper path controls.
  • Mounting over important image directories accidentally.
  • Assuming container removal keeps all data safe.

Best practices

  • Use named volumes for persistent container data.
  • Use bind mounts mainly for development or controlled host paths.
  • Back up important volumes.
  • Document what data each volume stores.
  • Be careful with docker volume prune .

Related Melochip guides

  • Docker Learning Path
  • Docker Compose Beginner Guide

Official references

  • Docker volumes documentation
  • Docker bind mounts documentation

Did this help?

Yes No

Join the discussion

0 Comments

Ask questions, add context, or share what worked.

Sign in to join the discussion

No comments yet. Start the discussion.

More from Melochip Editorial

Related articles

Stay in the loop. Get new Melochip articles

Receive Melochip article updates when new articles are available. Explicit opt-in only.

No pre-checked boxes. Unsubscribe support is part of the subscriber foundation.