Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

Docker Volumes vs. Bind Mounts: A Step-by-Step Guide

Use a named Docker volume for persistent application state and a bind mount when the host and container need the same files. Learn the commands, checks, and pitfalls.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a Docker volume for persistent application data Docker should manage; use a bind mount when a container and host need to access the same specific files or directory. The right choice depends on who owns the data and whether it needs to be directly visible on the host—not on a universal claim that one mount type is faster or better.

Docker volumes vs. bind mounts: what is the difference?

Both mount data into a container at a path the application can use. With a volume, Docker manages the storage location. With a bind mount, you choose a file or directory on the Docker daemon’s host and map it into the container. Docker describes volumes as its preferred mechanism for persisting data generated by or used by containers (Docker’s volumes documentation).

As an Amazon Associate I earn from qualifying purchases.

Decision point Volume Bind mount
Who chooses the source location? Docker manages the volume location. You specify a host path.
Typical use Persistent application or database data; data used by more than one container. Source code, configuration, build artifacts, or output that must be shared with the host.
Host visibility Managed by Docker; directly manipulating its data from the host is not the usual supported workflow. The selected host files are deliberately shared.
Portability Less dependent on a particular host directory layout. Depends on the host path and Docker daemon environment.
Main risk It remains after its container is removed, so it has a separate cleanup lifecycle. Read-write by default; it can expose or change host files, and it can obscure files already at the container destination.

Choose the mount type by identifying the data owner

Choose a named volume for persistent application state

For database files or other state that should survive container replacement, a named volume is a sensible default. The container can be removed and recreated while the volume remains available. A volume is persistent storage, not by itself an independent backup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a bind mount for files shared with the host

Use a bind mount when the host and container need the same working directory, source tree, configuration file, or output directory. Docker’s definition is a host file or directory mounted into a container (Docker’s bind-mount documentation).

Use the writable container layer only for disposable data

Files written only to a container’s writable layer do not survive destruction of that container. Put data that must persist in a volume or bind mount, according to who needs to manage and access it (Docker’s storage overview).

Use tmpfs for temporary in-memory data

A tmpfs mount is a third option for data that should live in memory rather than persist after the container stops or restarts. It is not a substitute for persistent application storage (Docker volumes documentation; Docker storage overview).

Step 1: Choose the container destination path

Find the absolute path the application reads or writes inside the container, such as /var/lib/app for application data or /app for a working directory. The destination must be an absolute path (Docker’s docker container run reference). Mounting at a different path will not make the application use the data automatically.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 2: Create a named volume for persistent data

Create the volume, then attach it at the application’s data path. Replace IMAGE with the image you intend to run and confirm that /var/lib/app is the correct path for that image.

docker volume create app-data
docker run --name app 
  --mount type=volume,src=app-data,dst=/var/lib/app 
  IMAGE

Docker can create a volume when a container starts if the named volume does not already exist, but creating it explicitly makes its separate lifecycle easier to see (Docker’s volumes documentation).

Step 3: Bind-mount a host directory when files must be shared

From the project directory, this example maps the current directory to /app in the container:

docker run --name dev 
  --mount type=bind,src="$(pwd)",dst=/app 
  IMAGE

This mount is read-write by default. If the container only needs to read the project files, make it read-only:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker run --name dev 
  --mount type=bind,src="$(pwd)",dst=/app,readonly 
  IMAGE

Path handling varies by operating system and Docker Desktop setup. The bind source must be a path available to the Docker daemon—not merely a path on the CLI client’s machine. With a remote daemon, a local client directory is not automatically available to the server; Docker Desktop mediates host paths through its environment (Docker’s bind-mount documentation).

Step 4: Verify the configured mount

Inspect the container and check its Mounts section for the source, destination, and mount type:

docker inspect app

For a named volume, confirm the expected volume is attached at the application path. For a bind mount, confirm the source is the intended host directory and the destination is the path the application uses.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Step 5: Avoid common data and access mistakes

Check the bind source before starting

The explicit --mount form normally fails if a bind source path does not exist. Its bind-create-src option can create the source directory. By contrast, the -v or --volume shorthand creates a missing host source as a directory, which can turn a mistyped path into a confusing empty mount. Docker recommends the more explicit --mount form (Docker’s bind-mount documentation; run command reference).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Remember that bind mounts can change host files

A process in the container can modify or delete files under a read-write bind mount. Use readonly when the container does not need write access, and avoid mounting sensitive host paths unless that access is intentional (Docker’s bind-mount documentation).

Best Value
Docker Container Linux Devops Programming Coding T-Shirt
  • Docker, Docker Swarm, Docker Compose, Programmer, Developer, Coding, Programming, Software Engineer, Code, DevOps, Deploy, Deployment, Kubernetes, Salt, Puppet, Chef, Terraform, Container, AWS, Azure, Cloud, Geek, Funny, Computer, Software, Tech, IT
  • Integration, Scrum, Compile, Compilation, Science, Bug, Debug, Python, Linux, Java, Javascript, Scala, Dotnet, Kotlin
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Do not mount over files you still need in the image

A bind mount placed over a non-empty directory in the container obscures that directory’s existing contents for as long as the mount is present. If files seem to disappear after adding a mount, check whether the destination overlaps files supplied by the image (Docker’s bind-mount documentation).

Remove volumes deliberately

Removing a container does not remove its named volume. Volume removal is a separate action, and docker volume prune removes unused volumes; check what data they hold before pruning (Docker’s volumes documentation).

Use the same distinction in Docker Compose

In Compose, declare a named volume at the top level and attach it to a service under that service’s volumes list. A bind mount specifies a host path and a container target. If multiple services need the same named volume, each service must be configured to use it (Docker’s Compose volumes reference).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
services:
  app:
    image: IMAGE
    volumes:
      - app-data:/var/lib/app
      - ./project:/app:ro

volumes:
  app-data:

Here, app-data is a named volume for persistent application data, while ./project is a host path mounted read-only at /app. Confirm that the relative path and container destination suit your project and service.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.