[linux] 修改docker端口映射


本文总阅读量

方法一:
1、关闭docker容器
docker stop 9656305ad917
2、关闭docker进程
systemctl stop docker
3、修改容器对应的配置文件
cd /var/lib/docker/container/<containid>
vim config.v2.json

1
2
3
4
5
"Config":{
....
"ExposedPorts":{"9999/tcp":{}},
....
}

如果配置文件中不存在ExposedPorts要自己手动加上,然后修改Ports内容,默认为null
vim config.v2.json

1
"Ports":{"9999/tcp":[{"HostIp":"0.0.0.0","HostPort":"9999"}]}

修改hostconfig.json:
vim hostconfig.json

1
"PortBindings":{"9999/tcp":[{"HostIp":"","HostPort":"9999"}]}

4、添加完成端口映射之后重启启动docker进程
systemctl start docker
5、启动容器
docker start 9656305ad917
6、查看容器的端口映射,9999端口映射添加成功

1
2
3
shell > docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9656305ad917 centos "/bin/bash" 28 hours ago Up About an hour 0.0.0.0:9999->9999/tcp jenkins

方法二:
1、停止容器
docker stop b693d1c304c5
2、从容器创建一个新的镜像
docker commit -m="install jenkins" -a="zeven0707" b693d1c304c5 zeven0707/jenkins:v1
3、启动提交后的镜像,并指定端口
docker run --name jenkins -p 9999:9999 -td zeven0707/jenkins:v1

目录

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog