--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.
It might be also worth noticing that in official Ubuntu images from Docker Hub iptables
package is not installed.
So general instruction should be
apt-get install iptables
- run docker container with
--net=host
and --cap-add=NET_ADMIN
--cap-add=NET_RAW
options.
Also, if you have a docker image that is missing iptables
package, and you don't want to create a custom image from it, you may run container with iptables
in the same network space. E.g. if you have container container-without-iptables
running, and you want to start some container-with-iptables
in the same network namespace, you can do:
docker run -it --pid=container:container-without-iptables --net=container:container-without-iptables --cap-add sys_admin container-with-iptables