简体   繁体   中英

Docker shared volume creation

I am trying to create a docker volume which will be shared between 2 hosts. Let's say that I have two hosts A and B. When the volume is created on host A with the following command:

docker volume create --driver local --opt type=nfs --opt o=addr=B,rw --opt device=:/tmp/dir --name foo

After inspection of volume, the result is the following:

  docker volume inspect foo
 [
    {
    "Name": "foo",
    "Driver": "local",
    "Mountpoint": "/var/lib/docker/volumes/foo/_data",
    "Labels": {},
    "Scope": "local"
    }
 ]

My question is: Why Mountpoint directory of volume doesn't point to directory /tmp/dir, but to default docker volume location? How I can consider that the data in directory host B/tmp/dir will be sharable?

Thanks in advance!

The volume you created does not match the inspect output. This would indicate that your volume create command failed, or perhaps you're checking the wrong host for the volume. With the current version of docker, the expected output is:

$ docker volume create --driver local --opt type=nfs \
         --opt o=addr=10.10.10.10,rw --opt device=:/path/to/dir nfs_test

$ docker volume inspect nfs_test                                       
[
    {
        "CreatedAt": "2018-02-18T12:10:03-05:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/home/var-docker/volumes/nfs_test/_data",
        "Name": "nfs_test",
        "Options": {
            "device": ":/path/to/dir",
            "o": "addr=10.10.10.10,rw",
            "type": "nfs"
        },
        "Scope": "local"
    }
]

The output you produced matches a local volume created without any options:

$ docker volume create foo

$ docker volume inspect foo
[
    {
        "CreatedAt": "2018-02-18T12:10:51-05:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/home/var-docker/volumes/foo/_data",
        "Name": "foo",
        "Options": {},
        "Scope": "local"
    }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM