12

Is there any performance difference between following docker named volumes vs bind mounted volumes? If yes, how much numbers are we talking about?

  1. Docker volume example:
docker run -v mysql:/var/lib/mysql mysql:tag
  1. Docker bind mount example:
docker run -v /path/to/mysql-data:/var/lib/mysql mysql:tag

These containers are used for mostly databases like elasticsearch, mysql and mongodb. Which one should I prefer?

1
  • 1
    afaik there's no difference. Obviously if the mapped folder on the host is local.
    – Stefano
    Commented Nov 1, 2020 at 8:42

2 Answers 2

26

On a couple of platforms (MacOS, Windows with WSL 2) bind mounts are known to be especially slow.

Beyond that, you shouldn't see a perceptible performance difference between named volumes, the container filesystem, files in the image (regardless of the number of layers), or bind mounts (particularly on native Linux).

A good general rule might be to use bind mounts for config files and log files, where I/O is relatively rare but you as a human need to access the files directly; named volumes for database storage and other content where I/O is relatively frequent but as a human you can't directly read the files; and the image itself for your application code.

4
  • 1
    I'm definitely not an expert, but that Windows link seems to be making recommendations about where to bind mount rather than comparing bind mounts and volumes, specifically recommending bind mounting to another Linux container instead of the Windows file system.
    – xdhmoore
    Commented Nov 29, 2020 at 1:19
  • 1
    Why would WSL 2 be slow (assuming that the bind mount is in the Linux file system and not the Windows file system)
    – Zach Smith
    Commented May 13, 2022 at 10:44
  • "but as a human you can't directly read the files" why would that be important? What if you have a case where I/O is frequent but the files are ones that humans want to read?
    – MarkR
    Commented Jul 19, 2024 at 3:21
  • As a human being you can't exercise the I/O system enough to personally experience the performance issues. You might read one file every several seconds compared to wanting to read thousands of files in a single second. Editing, say, a single source file will almost always see fine to you, but when your language runtime wants to read an entire bind-mounted library tree, it can be visibly slow.
    – David Maze
    Commented Jul 19, 2024 at 10:40
0

In Windows there is a big performance hit if you set bind mounts on the Windows file system and not on the WSL file system:

docker run -v \wsl$<DistroName>\path\to\mysql-data:/var/lib/mysql mysql:tag

"We recommend against working across operating systems with your files, ..... For the fastest performance speed, store your files in the WSL file system if you are working in a Linux..."

https://learn.microsoft.com/en-us/windows/wsl/setup/environment?source=recommendations

"Files can be accessed across the operating systems, but it may significantly slow down performance."

https://learn.microsoft.com/en-us/windows/wsl/setup/environment?source=recommendations#file-storage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.