What Is The Difference Between Binding Mounts And Volumes While Handling Persistent Data In Docker Containers?

后端 未结 4 580
刺人心
刺人心 2021-02-01 02:20

I want to know why we have two different options to do the same thing, What are the differences between the two.

4条回答
  •  粉色の甜心
    2021-02-01 03:01

    Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory structure of the host machine, volumes are completely managed by Docker. Volumes are often a better choice than persisting data in a container’s writable layer, because a volume does not increase the size of the containers using it, and the volume’s contents exist outside the lifecycle of a given container. More on

    Differences between -v and --mount behavior

    Because the -v and --volume flags have been a part of Docker for a long time, their behavior cannot be changed. This means that there is one behavior that is different between -v and --mount.

    If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory.

    If you use --mount to bind-mount a file or directory that does not yet exist on the Docker host, Docker does not automatically create it for you, but generates an error. More on

    Docker for Windows shared folders limitation

    Docker for Windows does make much of the VM transparent to the Windows host, but it is still a virtual machine. For instance, when using –v with a mongo container, MongoDB needs something else supported by the file system. There is also this issue about volume mounts being extremely slow. More on

提交回复
热议问题