注意:议映射端口尝试-p 8080:8081 的形式,如若不行再尝试该方法,在宿主机执行下面该防火墙规则指令

# iptables -t nat -A PREROUTING -d 宿主机IP -p tcp -m tcp --dport 宿主机端口 -j DNAT --to-destination 容器IP:容器端口



如果需要将192.168.1.2容器上的443端口映射到宿主机(192.168.2.140)的443端口:

# iptables -t nat -A PREROUTING -d 192.168.2.140 -p tcp -m tcp --dport 443 -j DNAT --to-destination 192.168.1.2:443


查看规则

# iptables -t nat -L


清除规则

# iptanbles -t nat -F