原文地址:https://stackoverflow.com/questions/28302178/how-can-i-add-a-volume-to-an-existing-docker-container
I've successfully mount /home/<user-name>
folder of my host to the /mnt
folder of the existing (not running) container. You can do it in the following way:
-
Open configuration file corresponding to the stopped container, which can be found at
/var/lib/docker/containers/99d...1fb/config.v2.json
(may beconfig.json
for older versions of docker). -
Find
MountPoints
section, which was empty in my case:"MountPoints":{}
. Next replace the contents with something like this (you can copy proper contents from another container with proper settings):
"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}}
or the same (formatted):
"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
}
}
- Restart the docker service:
service docker restart
This works for me with Ubuntu 18.04.1 and Docker 18.09.0