skip to Main Content

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


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

    Login or Signup to reply.
  2. The -v option on docker 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,

    docker run -v ./data:/data myimage
    

    creates a bind mount, whereas

    docker run -v data:/data myimage
    

    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

    -v /opt/myconfig:/run/db_config
    

    Mounts are read/write per default, so there’s no reason to specify that.

    You can read more here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search