docker,

Docker: volumes vs bind mounts

Feb 28, 2023 · 1 min read · Post a comment

There are two types of Docker volumes where data could be stored outside the container’s filesystem: volumes and bind mounts. So, what’s the difference?!

Prerequisites

  • Docker

Solution

The main difference between these two consists on how they are managed and where they are located.

Volumes are managed by Docker’s engine and are stored in a specific location on the host file system, usually under /var/lib/docker/volumes/. Volumes can be easily shared and reused between containers, and they are persistent even after the container is deleted.

In lieu of, bind mounts are specified by the user when the container is started and can be located anywhere on the host file system. Basically, they are a mapping between a directory on the host file system and a directory inside the container. Unlike volumes, bind mounts are not managed by Docker and are not persistent - if the container is deleted, the data in the bind mount is also deleted.

Conclusion

Overall, the choice between using a volume or a bind mount will depend on the use case and app requirements. Volumes are recommended for persistent data storage, while bind mounts may be more suitable for temporary or ad-hoc data storage needs while in the development and testing stage.

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.