在对已经运行的docker容器动态添加端口映射(expose 端口)
iptables -t nat -A DOCKER -p tcp --dport 10051 -j DNAT --to-destination 172.17.0.3:20022
iptables -t nat -A POSTROUTING -j MASQUERADE -p tcp --source 172.17.0.3 --destination 172.17.0.3 --dport 20022
iptables -A DOCKER -j ACCEPT -p tcp --destination 172.17.0.3 --dport 20022
增加宿主机10051->容器20022的端口映射。
原文链接:Docker 容器动态增加映射端口,转载请注明来源!