Docker 修改容器运行参数
修改 docker 容器的挂载路径
原来指令 -v /opt/jenkins:/var/jenkins_home 期望指令 -v /opt/jenkins:/var/jenkins_home -v /opt/data:/opt/data 场景:原来容器中的 -v 参数需要增加
- 停止所有 docker 容器
sudo docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)
- 停止 docker 服务
sudo service docker stop
- 修改对一个容器的配置的信息
- 修改 hostconfig.json
/var/lib/docker/containers/
"Binds": ["/opt/jenkins:/var/jenkins_home"]
/var/lib/docker/containers/
"Binds": ["/opt/jenkins:/var/jenkins_home", "/opt/data:/opt/data"]
- 修改 config.v2.json
/var/lib/docker/containers/
"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/
"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 中很多参数都不是必须的,按需设置就行
- 启动 docker 服务
service docker start
- 启动需要修改的容器
docker start <container id>