我已成功将/home/<user-name>
主机的/mnt
文件夹安装到现有(未运行)容器的文件夹中。您可以通过以下方式进行操作:
打开对应于已停止容器的配置文件,该文件可以在以下位置找到/var/lib/docker/containers/99d...1fb/config.v2.json
(可能config.json
适用于旧版本的docker)。
查找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
docker
标签在此处发布的问题为34k +,远远超过这两个站点stackoverflow.com/questions/tagged/docker