场景:docker搭建的jenkins通常需要配置很多开发环境,当要更换挂载目录,每次都需要删除容器重新运行,不在挂载目录的环境通常不会保留。
先给一个参考博客docker不删除容器,修改容器挂载或其他_jenkins 修改容器挂载docker-CSDN博客
自己记录一下:
1.docker ps 查找容器id
root@hcss-ecs-ed4e:/newdir2/jenkins_node/workspace# docker ps |grep jenkins
14b052d9faa2 jenkins_backup:2024_0428 "/usr/bin/tini -- /u…" 34 minutes ago Up 5 seconds 50000/tcp, 0.0.0.0:8086->8080/tcp, :::8086->8080/tcp
例如 我的jenkins容器的id是14b052d9faa2
2.进入该容器的配置文件中
root@hcss-ecs-ed4e:/# cd /var/lib/docker/containers/
root@hcss-ecs-ed4e:/var/lib/docker/containers# ls
0f15e598a9f9838f1b1f99cfa9fb1da6085fc738273bbe7e365ce44ee5caeb14 60a53359d4bd411b2ebe1b32a7407680bf9caf1b37efb28ff3c871e24934c727
104dc2059f18fb9b37cc7841619561d2e1f44791d018096a763399fa5e29e44a 7651c906870f63176e65b6e083c754acf72df719d849d99b820b7906d0172732
14b052d9faa25d48d72dc95938e114e1dc3febb1ec98ce7a12c46e65899d2258 7754c9f68dd25ab3b4653b6cc7b992b65067cbc75a117088b68a803daa0edbbc
18ae40115e480ddee7180caab2ebadeeffb5e360cc9f18958e50da242c132f6b 86c811bbce563fc48aa4caaef5416eb907069decdb1a7045ec4dbbf31f68995b
375a566233b91bd71ff3851e308f63fa9ef13be5e4316de6f3d1b2159a6b7d73 8ecbf13f4c075bc65536edd05fc43f862976f2e0ef3bda2827516e321c017896
3d0804973eeca30af28787b7926ba933be8dd1d4710a90dc7b720f6f55d70763 959273766a1f09b6de41bf2cdbe9cc47ad9316ca6d136b2622288d2ac842c56f
3fef73e067fa037c1fd9a5d88700400508763df4a30045e20d5d81a716cbb317 965dcbae8a05dbdd4d48b04491a3f65089056d5fc1d49efe672caa432b307c49
4002a31043c4d8f6fc1daa657177a24c580a3b710dd160a01431bfd51feef023 c4d85b9beab6a25da7893363c7fd672c2995a40b2bc72323dfd18f67c45a13ab
4e392f89098b3a390fef00a51361b3994da92a88ed2ea19ca17e520a05b5684f cab200bf1f3e5ffc9300c56f65687c1061da939c59cb986211db3dad50fa91b0
4edb56dcd29114c0e1f59a194dbaf5e750af394e9a31ae224ffbebcfa8130218 d9e1398e055e4169c41c9ffea9f026f7b47d882a8f7bd54deabacd9f0539be67
5096180c4726e53d529036f6c67c87e352d65fce778d83700b8a03fb706996e8 e1596d779f2f61c80d9aa5921a17e8f18178a6b969a084dbedd3a0332a2cb6f7
56315a450a5133c905b84c22690427010ea4edbfde7c653d8e528970eb528e62 f2518dd532ba41a8f9a6a527c2dfa1e2f285080d7cde282ba826d683696f4ac9
5d8d3e8e9cbba2319a7a834569d916e7cc477b5388322a1668e486b016562dc6 f803fe476c766ada932508dc6cb37689ba41b0f37d0a377af2ef91bf427102a9
5e98e0b4a42edde4161ea283b62d0dffee94bf1f264c1b11b1a0f9618e253748
root@hcss-ecs-ed4e:/var/lib/docker/containers# cd 14b052d9faa25d48d72dc95938e114e1dc3febb1ec98ce7a12c46e65899d2258/
root@hcss-ecs-ed4e:/var/lib/docker/containers/14b052d9faa25d48d72dc95938e114e1dc3febb1ec98ce7a12c46e65899d2258# ls
14b052d9faa25d48d72dc95938e114e1dc3febb1ec98ce7a12c46e65899d2258-json.log checkpoints config.v2.json hostconfig.json hostname hosts mounts resolv.conf resolv.conf.hash
3.更改config.v2.json 中的MountPoints信息
数据看起来比较乱,直接复制到在线解析中解析,方便找到需要更改的挂载目录
备份一下,再把解析并更改的json文件粘贴过来即可
root@hcss-ecs-ed4e:/var/lib/docker/containers/14b052d9faa25d48d72dc95938e114e1dc3febb1ec98ce7a12c46e65899d2258# mv config.v2.json config.v2.json_back
root@hcss-ecs-ed4e:/var/lib/docker/containers/14b052d9faa25d48d72dc95938e114e1dc3febb1ec98ce7a12c46e65899d2258# vi config.v2.json
重启容器即可