前提:需要停止docker进程
1、找到容器的id
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1917d5ddeb3 nginx "nginx -g 'daemon of…" 5 weeks ago Up About a minute 80/tcp, 0.0.0.0:8001->8001/tcp nginx
2、进入宿主机容器的配置文件目录
cd /var/lib/docker/containers/b1917d5ddeb368036d77ddbe7cbf1d9dbec04b53540159428c183e104e562a58
3、给容器添加一个bind volume
将hostconfig.json中"Binds":[]修改为"Binds":["/test:/test"]
将config.v2.json中"MountPoints":{}修改为{"/test":{"Source":"/test","Destination":"/test","RW":true,"Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/test","Target":"/test"}}}
4、启动docker进程
systemctl start docker