标签:输出 保存 pos 文件路径 current path bind container 重启
原文:Docker修改容器的端口映射和挂载路径有时候因为某些原因需要修改容器的配置,如端口映射和挂载路径,但是如果删除容器后再重新运行,那么之前在容器内所做的修改就丢失了,本文提供了两种方法,可以在保留修改的同时修改配置参数。
docker stop CONTAINER
docker commit CONTAINER NEWIMAGE:TAG
docker run --name CONTAINER OPTIONS NEWIMAGE:TAG
docker inspect CONTAINER
{
"ResolvConfPath": "/var/lib/docker/containers/96b9323df1569e83c9945a9daab253c7c5e6cab35cd4b5eb19b16913e130cd14/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/96b9323df1569e83c9945a9daab253c7c5e6cab35cd4b5eb19b16913e130cd14/hostname",
"HostsPath": "/var/lib/docker/containers/96b9323df1569e83c9945a9daab253c7c5e6cab35cd4b5eb19b16913e130cd14/hosts",
"LogPath": "/var/lib/docker/containers/96b9323df1569e83c9945a9daab253c7c5e6cab35cd4b5eb19b16913e130cd14/96b9323df1569e83c9945a9daab253c7c5e6cab35cd4b5eb19b16913e130cd14-json.log",
}
截取部分输出,如上所示。其中,/var/lib/docker/containers/96b9323df1569e83c9945a9daab253c7c5e6cab35cd4b5eb19b16913e130cd14/即为配置文件夹,记录下路径后停止容器。
docker stop CONTAINER
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
-按ctrl+a+k,再按y确认即可kill掉这个screen
-使用ctrl+a+d可暂时退出这个screen,而如需再次进入则应当使用screen -dr,不能再次使用screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty,该命令会再次创建一个screen而产生一些莫名其妙的问题
cd /var/lib/docker/containers/96b9323df1569e83c9945a9daab253c7c5e6cab35cd4b5eb19b16913e130cd14/
需要同时修改该目录下hostconfig.json和config.v2.json两个文件
hostconfig.json
{
"PortBindings":{"8080/tcp":[{"HostIp":"0.0.0.0","HostPort":"22"}],
"9090/tcp":[{"HostIp":"0.0.0.0","HostPort":"9999"}]}
}
config.v2.json
{
"ExposedPorts":{"8080/tcp":{},"9090/tcp":{}}
}
hostconfig.json
{
"Binds": ["/data:/mnt/data", "/home/logs:/logs"]
}
config.v2.json
{
"MountPoints":{"/mnt/data":{"Source":"/data","Destination":"/mnt/data","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/data","Target":"/mnt/data"},"SkipMountpointCreation":false},
"/home/logs":{"Source":"/home/logs","Destination":"/logs","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/home/logs","Target":"/logs"},"SkipMountpointCreation":false}}
}
保存后退出screen并重启docker服务。
检查设置是否生效可以运行
docker inspect CONTAINER
在"Mounts"、"Ports"两个关键字中查看刚刚的配置有没有生效。
标签:输出 保存 pos 文件路径 current path bind container 重启
原文地址:https://www.cnblogs.com/lonelyxmas/p/12690378.html