dockercontainers

Docker bind mount directory vs named volume performance comparison


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?


Solution

  • 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.