docker修改容器绑定端口
1、关闭正在运行的容器
2、查看容器ID,docker ps -a
3、找到宿主机容器目录, cd /var/lib/docker/containers/f65c8e2e*
4、修改hostconfig.json
找到PortBindings,例如容器内的端口是50070,绑定的宿主机端口是5007:
"PortBindings":{"50070/tcp":[{"HostIp":"","HostPort":"5007"}]}
现在新添加容器内端口9000绑定宿主机8020:
"PortBindings":{"50070/tcp":[{"HostIp":"","HostPort":"5007"}],"9000/tcp":[{"HostIp":"","HostPort":"8020"}]}
5、修改config.v2.json
找到ExposedPorts,(如果没有,自己添加一个)
"ExposedPorts":{"50070/tcp":{}}
将新的端口补充进去
"ExposedPorts":{"50070/tcp":{},"9000/tcp":{}}
6、重启docker服务即可