Docker Community Forums

Share and learn in the Docker community.

How to expose ports with iptables?


(Verb5) #1

Hello
I have two containers both are postfix container,Container A has been create without exposing port 25 and container B with expose port 25. So i tried to mimic same iptables like the one generated for container B on my host machine but no luck. Is there anything else i should configure before i could get access to port 25 on container A. Also any easy way to expose ports on already created container ?

here are my iptables rules:

iptables -t nat -A DOCKER -p tcp  --dport 25 -j DNAT  --to-destination 172.17.0.4:25
iptables -t nat -A POSTROUTING -p tcp -s 172.17.0.4 -d 172.17.0.4  --dport 25 -j MASQUERADE
iptables -A DOCKER -p tcp -d 172.17.0.4 --dport 25 -j ACCEPT