9

I need to create a persistent volume for Docker. The volume must be named extra-addons and located in /mnt/.

I run this command:

sudo docker volume create /mnt/extra-addons

I got this error message:

Error response from daemon: create /mnt/extra-addons: "/mnt/extra-addons" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path

Note that when I simply run: sudo docker volume create extra-addons, I do not face this problem but when I inspect the volume in question using sudo docker inspect extra-addons, I see it is located in a place I do not want:

[
    {
        "CreatedAt": "2018-04-21T14:40:25+03:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/extra-addons/_data",
        "Name": "extra-addons",
        "Options": {},
        "Scope": "local"
    }
]

I mean I rather want to see the volume like this: /mnt/extra-addons

Any idea?

8

I found the solution:

I had to install local-persist plugin.

I had to mount the volume to create to the mount point as follows:

 sudo docker volume create -d local-persist -o mountpoint=/mnt/ --name=extra-addons

Check if I got what I expected:

sudo docker volume inspect extra-addons

Result:

[
    {
        "CreatedAt": "0001-01-01T00:00:00Z",
        "Driver": "local-persist",
        "Labels": {},
        "Mountpoint": "/mnt/",
        "Name": "extra-addons",
        "Options": {
            "mountpoint": "/mnt/"
        },
        "Scope": "local"
    }
]

That was what I am looking for.

4

If you don't want to install any plugins to your docker, I would recommend to create a symbolic link for your volume:

$ docker volume create <myVolume>
$ docker volume inspect <myVolume> 
[
    {
        "CreatedAt": "0001-01-01T00:00:00Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/<myVolume>/_data",
        "Name": "<myVolume>",
        "Options": {},
        "Scope": "local"
    }
]
$ mkdir /mnt/<myVolume>
# if you already have data in your volume, you should copy it to `/mnt/<myVolume>` now
$ sudo rm -rf /var/lib/docker/volumes/<myVolume>/_data
$ sudo ln -s /mnt/<myVolume> /var/lib/docker/volumes/<myVolume>/_data

Now feel free to use your volume as usual (with all your data beeing in /mnt as you wanted)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.