Installing iptables in docker container based on alpinelinux

Tharanga picture Tharanga · Jan 17, 2017 · Viewed 26k times · Source

I am writing a dockerfile and I need IPtables to be installed in docker container. I need to add a rule to the IP table as I am trying to run on "host" network mode and it seems I need install IPtables for this purpose. when I try to include the rule as follows I get the following error.

iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT


iptables v1.6.0: can't initialize iptables table `filter': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.

Is it possible to run iptables with root privileges.

Answer

Dmitriusan picture Dmitriusan · Jun 13, 2017

--privileged flag is not required anymore. Starting with Docker 1.2 you can now run your image with parameters --cap-add=NET_ADMIN and --cap-add=NET_RAW which will allow internal iptables.