Docker Volumes vs Bind Mounts: What to Use and When

Containers are temporary by design. Stop one and its filesystem goes with it, which is fine for code and terrible for a database. That is the problem docker volumes vs bind mounts solves: both give a container a place to keep data outside its own filesystem, but they store that data in different places, with different rules about who owns it and how it behaves on another machine.

Pick wrong and you get one of two failures. Use a bind mount for a database and the files land in a host folder with the wrong owner, so the database cannot start. Use a named volume for code you edit every day and your edits never reach the container, so you spend an hour debugging code that never ran. The choice is small, but it decides whether your data survives a restart and whether your workflow stays fast.

Docker volumes vs bind mounts: the core difference

A named volume is storage Docker manages. You name it, Docker creates it under its own data directory, and the container reads and writes through that name. A bind mount is a folder on your host that you point into the container, such as ./data:/var/lib/postgresql/data. The container sees your real folder, with your real files, your real permissions, and your real backup tools.

The practical difference is ownership. Docker owns the volume and handles permissions, drivers, and portability. You own the bind mount, so you control the files, but you also own the permission problems and the path differences between machines. A compose file that bind-mounts /home/firdaus/data breaks on a teammate’s laptop, while a named volume works everywhere the compose file runs.

When to use a named volume

Use a named volume for data the container owns and you rarely touch by hand. A docker named volume database setup is the default pick for Postgres and MySQL, and databases are the classic case. Postgres, MySQL, and Redis all keep their data in one folder, and a named volume keeps that folder alive across container restarts, rebuilds, and image updates. The volume survives docker compose down and only disappears when you delete it on purpose with docker compose down -v or docker volume rm.

Named volumes also fit caches, uploaded files, and any state the app writes while it runs. They work the same on Linux, Mac, and Windows, and Docker can back them with a driver for shared or remote storage when a single host stops being enough. List them with docker volume ls, inspect one with docker volume inspect pgdata, and back one up by running a short-lived container that mounts it and copies the files out:

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

If the app on that database is one of several sites sharing a host, our guide on how to isolate multiple sites on one VPS with Docker shows how volumes keep each site’s data separate. For the backup side of the same problem, read our guide to the best Linux server backup tools, including Restic, Borg, and Duplicacy before you trust a volume you have never restored from.

When to use a bind mount

Use a bind mount when you need to see and edit the files from the host. A docker bind mount development workflow mounts your code folder into the container, and local development is the main case: mount your code folder into the container so edits appear at once without a rebuild. Config files are the second case. Mounting an Nginx config or an app config file lets you change settings and restart the container without rebuilding the image.

Bind mounts also fit data that already lives somewhere specific, such as a folder your backup job already covers or a disk mounted at a known path on the server. The price is portability. The path is baked into the compose file or the run command, and the permissions of the host folder decide whether the container can read and write. A database that runs as user 999 inside the container will fail to write to a host folder owned by a different user, and the error looks like a database bug until you check the folder owner.

A quick comparison

The table below sums up the trade-off. Read the row that matches your data, not the one that matches your habit.

Question Named volume Bind mount
Who manages the files? Docker You, on the host
Works the same on every machine? Yes No, paths differ
Best for databases? Yes Only with care
Best for live code editing? No Yes
Easy to back up from the host? Needs a helper container Yes, it is a plain folder
Survives container removal? Yes Yes

There is also a third option worth knowing. A tmpfs mount keeps data in memory and drops it when the container stops, which fits temporary files and caches that must never touch disk. It is a niche pick, but the right one when a secret or a scratch file should vanish with the container.

Common mistakes and how to avoid them

The most common mistake is mounting a host folder over a folder the image already filled. Docker copies nothing into a bind mount, so the container starts with an empty folder where it expected config files or seed data. Named volumes behave differently: Docker copies the image folder contents into a fresh volume on first use. That one difference explains a whole class of “it worked yesterday” bugs.

The second mistake is forgetting that docker compose down -v deletes named volumes. It is a handy reset during development and a disaster on a server with live data. The third is skipping backups because the data “lives in Docker.” A docker volume backup routine belongs in your weekly checklist, not in your memory, because a volume you have never restored from is a backup you have never tested. It does not. It lives in a volume on a disk that can fail like any disk, so back it up on a schedule and test the restore. Our guide to setting up automatic encrypted backups for a small team covers a schedule you can run without thinking about it. Use named volumes for data the app owns, bind mounts for files you edit, and a backup for both.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.