Docker Volumes vs Bind Mounts: Know Where Your Data Lives
Choose storage by who manages the files, inspect the mount your container really uses, and plan a restore before the next upgrade.
TL;DR
- Use a named volume for app-owned data and a bind mount for host files you edit.
- Run docker inspect on the container and confirm a mount destination matches the app's real data directory.
- Docker Compose down with --volumes deletes named volumes, so plan a restore before upgrading.
A container can be recreated in seconds; discovering where it stored your files can take much longer. For an application that writes its own persistent data, start with a named Docker volume. For files you deliberately edit from the host, such as source code or a configuration file, a bind mount usually makes the relationship clearer.
The practical question is who manages the storage location. Docker manages a volume; you manage the source path of a bind mount. Both need a backup plan. This guide explains that choice for ordinary single-host Docker Engine and Compose setups, based on Docker's documentation rather than a storage performance benchmark.
Decide who needs to touch the files
Both mounts expose storage at a container destination, but the source is managed differently. A bind path belongs to the Docker daemon’s host; mounting persistence still requires a consistent backup and restore plan.
Imagine a small photo application with three kinds of files: its installed program, your uploaded photos and a configuration file you maintain. Treat these as separate responsibilities.
The installed program belongs in the image. Uploads must survive replacing the container. The configuration needs a deliberate source of truth, so you know which copy to edit during a change.
A useful starting decision is:
- App-managed files: choose a named volume when the application owns the contents and host-side editing is unnecessary.
- Host-managed files: choose a bind mount when a known host folder is part of the workflow, such as editing a local project in a container.
- Disposable output: decide whether it needs persistence at all. A scratch calculation can be rerun; the only copy of a family photo cannot.
Docker describes the ownership distinction in its volume documentation. A volume exists outside the container's writable layer. Recreating the container can reuse it, provided the replacement mounts the same volume at the path the application actually uses.
The last condition is where many recovery stories begin. Saving data in a persistent store is useful only when the application writes to that store.
In Compose, check the actual volume name as well as the name in your YAML. By default, volume names include the project name; a different project name can therefore select a different store. Docker's Compose volume reference explains the naming rules. If an app starts empty after redeployment, compare the old and new mount names before deleting either volume.
Read the mount that is actually running
Before changing anything, inspect the container. Substitute its actual name in this command:
docker inspect --type=container --format '{{json .Mounts}}' YOUR_CONTAINER This reads mount metadata rather than modifying it. Docker's inspect reference documents the JSON formatting helper and the type filter. The output may include several mounts; match each one to its destination inside the container.
Look for:
Type: whether this is avolumeorbindmount.Name: the named volume, when applicable.Source: the source on the Docker daemon's host.Destination: where the container sees it.RW: whether this mount is writable.
Now compare the destination with the application's documented data directory. A mount at /data does not protect files an application actually writes under /var/lib/example. The paths in this paragraph are illustrative; use the image vendor's real instructions.
Keep the relevant mount details in your deployment notes. Avoid posting the complete inspection output publicly: other sections can contain environment variables and details unrelated to the storage question.
Use a bind mount when the host path is intentional
A bind mount makes a host file or directory available inside the container. It is useful when a human or another host process owns that path, but it also creates a dependency on that host's layout.
Docker's bind-mount guidance highlights two consequential boundaries. A bind mount refers to the daemon host, which can differ from the computer running your Docker client. It is also writable by default, so a container process can change the mounted host files.
For a static configuration that the application only reads, prefer a read-only mount if the application supports it. Check RW afterwards. Do not make an application's required data directory read-only and expect normal writes to continue.
Suppose a service worked on your laptop but starts with an empty library on a server. Before concluding that Docker lost the library, compare the real source paths. You may have mounted a different, empty folder on the new host. Copying the Compose file alone does not copy the host folder it names.
Understand why existing image files disappear
Mounting storage over a directory can hide files that were already present there in the image. This is a visibility change at the mount point; it does not establish that the image itself was rewritten.
For example, imagine an image contains a default configuration at a directory that you then cover with an empty host folder. The application now sees that mounted folder at the same location. Rebuilding the image repeatedly will not fix a source path that still points to the wrong folder.
There is also a distinction between an empty volume's initial population and an existing volume's contents. Docker's volume documentation explains the default copy behaviour for a new empty volume. Do not treat that initial behaviour as an update synchronisation mechanism. A replacement image is not a migration plan for an already populated data store.
If a mount seems to hide something important, inspect the configuration and preserve the current data before recreating anything. Avoid “fixing” the symptom by deleting the store and hoping the application reconstructs it.
Know what Compose down removes
A named volume is persistent storage, but it is still removable. Docker's Compose down reference distinguishes the ordinary command from its --volumes option: the latter removes declared named volumes and attached anonymous volumes. External volumes are excluded from removal by Compose.
That is a reason to review a maintenance command before running it, especially when it was copied from a tutorial that assumes disposable development data. The option that resets someone else's demo can erase the state you wanted to preserve.
An anonymous volume creates another operational problem: surviving removal does not mean the next container automatically reconnects to the same anonymous volume. For data you need to identify and reuse, a named volume or an explicit bind path is easier to account for.
Make a restore test part of the choice
Before the next application upgrade, answer four questions in writing:
- Which exact store contains the authoritative data?
- Which supported method creates a consistent backup while the app or database is running?
- Where is the backup kept outside this Docker host?
- How will you restore it into an isolated test service and check its contents?
A directory copy of a running database may be inconsistent. For a concrete example, our SQLite backup guide demonstrates how a copied database file can miss committed changes. Use the database or application's supported backup method and retain any matching version information required for restoration. A volume's persistence answers a lifecycle question; it does not answer whether a backup captures a usable state.
For an illustrative photo service, a useful restore check is to open a known older photo, confirm a recent upload and check that the library's catalogue still matches its files. Pick equivalent checks for your application. “The container started” is too weak when the recovery goal is your data.
Choose the mount whose ownership fits the workflow, record its actual identity and test recovery before relying on it. The most useful storage configuration is one you can explain again when the original container is gone.
Subscribe
All the new articles in one Monday digest. Unsubscribe with one click.