Bind mounts

We have seen these earlier, but maybe we did not know what they are. Bind mounts take a specific file or folder and mount it within the container sandbox at a specified location, separated by :. The general syntax that we have used so far for this should look similar to the following:

$ docker run <run_params> 
-v /path/on/host:/path/on/container
<image>...

Newer Docker syntax for this functionality is making its way into becoming a standard where the -v and --volume is now being replaced with --mount, so you should get used to that syntax too. In fact, from here on out, we will use both as much as we can so that you are comfortable with either style, but at the time of writing this book, --mount is not yet as fully functional as the alternative so expect some interchanging depending on what works and what does not.

In particular here, at this time, a simple bind mount volume with an absolute path source just does not work with --mount style which is almost all the examples we have used so far which is why we have not introduced this form earlier.

With all that said and out of the way, unlike --volume, --mount is a <key>=<value> comma-separated list of parameters:

  • type: The type of the mount, which can be bind, volume, or tmpfs.
  • source: The source for the mount.
  • target: The path to the location in the container where the source will be mounted.
  • readonly: Causes the mount to be mounted as read-only.
  • volume-opt: Extra options for the volume. May be entered more than once.

This is a comparative version to the one we used for --volume:

$ docker run <run_params> 
--mount source=/path/on/host,target=/path/on/container
<image>...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.98.18