我已成功将主机的/home/<user-name> 文件夹挂载到现有(未运行)容器的/mnt 文件夹。您可以通过以下方式进行:
打开停止容器对应的配置文件,可以在/var/lib/docker/containers/99d...1fb/config.v2.json找到(对于旧版本的docker可能是config.json)。
查找MountPoints 部分,在我的情况下为空:"MountPoints":{}。接下来用类似这样的内容替换内容(您可以从另一个具有适当设置的容器中复制适当的内容):
"MountPoints":{"/mnt":{"Source":"/home/<user-name>","Destination":"/mnt","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/home/<user-name>","Target":"/mnt"},"SkipMountpointCreation":false}}
或相同(格式化):
"MountPoints": {
"/mnt": {
"Source": "/home/<user-name>",
"Destination": "/mnt",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/home/<user-name>",
"Target": "/mnt"
},
"SkipMountpointCreation": false
}
}
- 重启docker服务:
service docker restart
这适用于 Ubuntu 18.04.1 和 Docker 18.09.0