查看Container的IP地址
docker inspect <container name or id>| grep IPAddress
查看Container的映射的端口
docker port <container name or id> eg. docker port d8dac7399647
用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
查詢 映射關系