docker 给已经启动的容器添加目录映射(挂载目录)

1、在进入宿主机的配置文件目录

查看容器存放目录

docker info | grep Root
cd /var/lib/docker/containers/容器id

2、修改 config.v2.json

添加宿主机/home/nginx映射到容器的/import
找到MountPoints,添加以下文字,如果省略有内容,注意加逗号

“MountPoints”: {
.....省略 注意逗号

"/import": {"Source": "/home/nginx","Destination": "/import","RW": true,"Name": "","Driver": "","Type": "bind","Propagation": "rprivate","Spec": {"Type": "bind","Source":"/home/nginx","Target": "/import"},"SkipMountpointCreation": false}

}

3、修改 hostconfig.json,添加以下红色文字

添加"Binds":["/home/nginx:/import"]

4、重启docker和容器

systemctl start docker
docker start 容器名

你可能感兴趣的:(docker 给已经启动的容器添加目录映射(挂载目录))