I have a web service running on port 8080, which is made available on port 80 through IPTables like so:

iptables -t nat -A OUTPUT -p tcp -d --dport 80 -j REDIRECT --to-port 8080

This works, however attempting to reach inside a Docker container fails. I assume this is because lo within the container is a separate device inside a network namespace. Thus I attempted to do the following:

iptables -t nat -A OUTPUT -p tcp -d --dport 80 -j REDIRECT --to-port 8080

where is the range assigned to the docker0 bridge interface. Connections to (the IP assigned to docker0) still fail inside the container.

There are no firewall rules other than the standard set created by Docker.

Why is this forwarding rule still failing?


  • Ubuntu 14.04 (3.13.0-36-generic)
  • Docker 1.2.0

In the end, I fixed this by using a slightly different range and inserting a PREROUTING rule before dockers.

iptables -t nat -I PREROUTING 1 -p tcp -d --dport 80 -j REDIRECT --to-port 8080

Your first rule redirects anything in the network to the local webservice, instead of what you probably intentioned to be things directed at lo.

Assuming you lo interface has IP (which it almost certainly does) try this instead:

iptables -t nat -A OUTPUT -p tcp -d --dport 80 -j REDIRECT --to-port 8080

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.