Docker

Docker:在特定目錄中創建持久卷

  • July 23, 2019

我需要為 Docker 創建一個持久卷。該卷必須命名extra-addons並位於/mnt/.

我執行這個命令:

sudo docker volume create /mnt/extra-addons

我收到此錯誤消息:

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

請注意,當我簡單地執行:時sudo docker volume create extra-addons,我不會遇到這個問題,但是當我使用檢查有問題的捲時sudo docker inspect extra-addons,我發現它位於我不想要的地方:

[
   {
       "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"
   }
]

我的意思是我更希望看到這樣的音量:/mnt/extra-addons

任何的想法?

我找到了解決方案:

我必須安裝本地持久外掛。

我必須將要創建的捲安裝到安裝點,如下所示:

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

檢查我是否得到了我的預期:

sudo docker volume inspect extra-addons

結果:

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

這就是我要找的。

引用自:https://unix.stackexchange.com/questions/439106