docker-修改容器挂载目录的3种方法小结

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker-修改容器挂载目录的3种方法小结相关的知识,希望对你有一定的参考价值。

参考技术A

方式一:修改配置文件(需停止docker服务)

1、停止docker服务

systemctl stop docker.service(关键,修改之前必须停止docker服务)

2、vim /var/lib/docker/containers/container-ID/config.v2.json

修改配置文件中的目录位置,然后保存退出

3、启动docker服务

4、启动docker容器

docker-修改容器挂载目录

1、停止容器

systemctl stop docker.service

# 一定要停止容器,不然修改无效

#检查容器是否已停止
docker ps

2、修改挂载点信息

"MountPoints": {
        "/etc/gitlab-runner": {
            "Source": "/opt/gitlab-runner/config",
            "Destination": "/etc/gitlab-runner",
            "RW": true,
            "Name": "",
            "Driver": "",
            "Type": "bind",
            "Propagation": "rprivate",
            "Spec": {
                "Type": "bind",
                "Source": "/opt/gitlab-runner/config",
                "Target": "/etc/gitlab-runner"
            },
            "SkipMountpointCreation": false
        },
        "/home/gitlab-runner": {
            "Source": "",
            "Destination": "/home/gitlab-runner",
            "RW": true,
            "Name": "27cbde18a296ee3f8cf2744d108e04fec26d0a75ecd1383d9deb4a5f802e26f7",
            "Driver": "local",
            "Type": "volume",
            "Spec": {},
            "SkipMountpointCreation": false
        },
        "/var/run/docker.sock": {
            "Source": "/var/run/docker.sock",
            "Destination": "/var/run/docker.sock",
            "RW": true,
            "Name": "",
            "Driver": "",
            "Type": "bind",
            "Propagation": "rprivate",
            "Spec": {
                "Type": "bind",
                "Source": "/var/run/docker.sock",
                "Target": "/var/run/docker.sock"
            },
            "SkipMountpointCreation": false
        },
        "/opt/maven": {
            "Source": "/opt/maven",
            "Destination": "/opt/maven",
            "RW": true,
            "Name": "",
            "Driver": "",
            "Type": "bind",
            "Propagation": "rprivate",
            "Spec": {
                "Type": "bind",
                "Source": "/opt/maven",
                "Target": "/opt/maven"
            },
            "SkipMountpointCreation": false
        }
    }

# 建议复制一个已有的挂载点,修改成添加的路径,再追加到最后面,要注意在倒数第二个的结尾加“,”

3、重启docker

systemctl start docker.service

# 确认容器是否启动
docker ps

4、进去容器查看

docker exec -it 容器ID  /bin/bash

以上是关于docker-修改容器挂载目录的3种方法小结的主要内容,如果未能解决你的问题,请参考以下文章

简年8:Docker 容器数据卷挂载小结

docker-修改容器的挂载目录三种方式

docker挂载文件后变成目录

docker容器之dockerfile镜像

如何修改运行中的docker容器的端口映射和挂载目录

docker添加挂载目录或者添加端口