Upon inspect my docker container info shows:
"HostConfig": {
"Binds": [
"/opt/myconfig:/run/db_config:rw"
],
I suspect this works as a mounting volumes with:
-v mysql-data:/var/lib/mysql
But, I need to understand the difference between -v and whatever cmd created the Binds. Which cmd as -v could create the Binds entry?
2
Answers
-v or –volume: This option is used by users in the docker run command to set up a bind mount at the time of the container run, mapping a host path to a container path.
Binds in HostConfig: This only visible when you inspect a container, shows the actual bind mounts applied to the container as configured by -v or –mount or –volume. It’s not a command but a record of the mount configuration. it is recorded as part of the docker image build
If we summerise, -v will create the mount, and Binds will reflect it in Docker’s internal configuration.
The
-v
option ondocker run
can map both a docker volume or a host directory.If the thing you’re mapping is a directory or a file, docker creates a bind mount. If it’s not, then docker creates a volume mapping.
For example,
creates a bind mount, whereas
creates a volume mount.
You can also be more explicit by using the
--mount
option instead. Using--mount
is recommended, but as it’s more verbose, most people use the-v
option.In your example, what created the bind mount would be an option like this
Mounts are read/write per default, so there’s no reason to specify that.
You can read more here.