查看Container的IP地址

docker inspect <container name or id>| grep IPAddress

查看Container的映射的端口

docker port <container name or id>
eg.
docker port d8dac7399647
docker port hfq-jedi-zxf-eden

用iptables查看容器映射情况

iptables -t nat -nvL
iptables -t nat -nvL --line-number

举例新增端口的映射

##将主机31101 映射到 容器 6379端口
iptables -t nat -A PREROUTING  -p tcp -m tcp --dport 31101 -j DNAT --to-destination  192.168.42.2:6379

保存iptables规则

iptables-save

说明

192.168.42.2 是根据 docker inspect <container name or id>| grep IPAddress 的结果

端口映射完毕后,不能通过docker port d8dac7399647查询到结果

可以通过
iptables -t nat -nvL | grep 192.168.42.2
查询 映射关系
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐