Docker 修改容器运行参数

修改 docker 容器的挂载路径

原来指令 -v /opt/jenkins:/var/jenkins_home 期望指令 -v /opt/jenkins:/var/jenkins_home -v /opt/data:/opt/data 场景:原来容器中的 -v 参数需要增加

  1. 停止所有 docker 容器
sudo docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)
  1. 停止 docker 服务
sudo service docker stop
  1. 修改对一个容器的配置的信息

/var/lib/docker/containers//hostconfig.json 修改前

"Binds": ["/opt/jenkins:/var/jenkins_home"]

/var/lib/docker/containers//hostconfig.json 修改后

"Binds": ["/opt/jenkins:/var/jenkins_home", "/opt/data:/opt/data"]

/var/lib/docker/containers//config.v2.json 修改前

"MountPoints": {
    "/var/jenkins_home": {
        "Source": "/opt/jenkins",
        "Destination": "/var/jenkins_home",
        "RW": true,
        "Name": "",
        "Driver": "",
        "Type": "bind",
        "Propagation": "rprivate",
        "Spec": {
            "Type": "bind",
            "Source": "/opt/jenkins",
            "Target": "/var/jenkins_home"
        },
        "SkipMountpointCreation": false
    }
}

/var/lib/docker/containers//config.v2.json 修改后

"MountPoints": {
    "/var/jenkins_home": {
        "Source": "/opt/jenkins",
        "Destination": "/var/jenkins_home",
        "RW": true,
        "Name": "",
        "Driver": "",
        "Type": "bind",
        "Propagation": "rprivate",
        "Spec": {
            "Type": "bind",
            "Source": "/opt/jenkins",
            "Target": "/var/jenkins_home"
        },
        "SkipMountpointCreation": false
    },
    "/opt/data": {
        "Source": "/opt/data",
        "Destination": "/opt/data",
        "RW": true,
        "Propagation": "rprivate"
    }
}

这里可以看出 MountPoints 中很多参数都不是必须的,按需设置就行

  1. 启动 docker 服务
service docker start
  1. 启动需要修改的容器
docker start <container id>
Table of Contents