1- 获取docker容器物理存放位置
docker inspect cdh01
需要修改的配置文件路径:
例如:"HostsPath": "/var/lib/docker/containers/f737dcc478797b3130889515835157c7b88d394c69dadea7afb017d29a452b9f/
红色的是随机数,是容器的CONTAINER ID的缩写:
[root@dma01 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a5b053e50871 cdh03:v1 "/usr/sbin/init" 11 months ago Up 2 hours 0.0.0.0:22013->22/tcp cdh03 3b3db7c49c25 cdh02:v1 "/usr/sbin/init" 11 months ago Up 2 hours 0.0.0.0:22012->22/tcp cdh02 f737dcc47879 cdh01:v1 "/usr/sbin/init" 11 months ago Up 2 hours 0.0.0.0:12346-12347->12346-12347/tcp, 0.0.0.0:22011->22/tcp, 0.0.0.0:2182->2181/tcp, 0.0.0.0:7181->7180/tcp, 0.0.0.0:8021->8020/tcp, 0.0.0.0:8889->8887/tcp, 0.0.0.0:9102->9101/tcp, 0.0.0.0:9105->9104/tcp cdh01 [root@dma01 ~]# |
2- 停止docker容器
docker stop cdh01
docker stop cdh02
docker stop cdh03
3- 修改容器对应的hostconfig.json文件
备份hostconfig.json文件
增加需要映射的端口,如果有多个,用逗号分割
格式:"2181/tcp":[{"HostIp":"","HostPort":"2182"}] 表示将容器的2181端口,映射成宿主机的2181端口
"2181/tcp":[{"HostIp":"","HostPort":"2182"}],"8020/tcp":[{"HostIp":"","HostPort":"8021"}],"9101/tcp":[{"HostIp":"","HostPort":"9102"}],"9104/tcp":[{"HostIp":"","HostPort":"9105"}],"7180/tcp":[{"HostIp":"","HostPort":"7181"}]
4- 修改容器对应的config.v2.json
备份config.v2.json文件
增加映射出的容器端口,如果有多个,用逗号分割
格式:"2181/tcp":{}
"2181/tcp":{},"8020/tcp":{},"9101/tcp":{},"9104/tcp":{},"7180/tcp":{}
5- 重启docker服务
systemctl restart docker
6- 启动docker容器
docker start cdh01
docker start cdh02
docker start cdh03
7- 验证端口映射结果
docker ps cdh01