方法一:
1、关闭docker容器docker stop 9656305ad917
2、关闭docker进程systemctl stop docker
3、修改容器对应的配置文件cd /var/lib/docker/container/<containid>
vim config.v2.json
1 | "Config":{ |
如果配置文件中不存在ExposedPorts要自己手动加上,然后修改Ports内容,默认为nullvim 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 | shell > docker ps |
方法二:
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