基于 alpinelinux 在 docker 容器中安装 iptables

Installing iptables in docker container based on alpinelinux

我正在编写一个 docker 文件,我需要将 IPtable 安装到 docker 容器中。我需要向 IP table 添加规则,因为我试图在 "host" 网络模式下 运行,似乎我需要为此目的安装 IPtables。当我尝试包含如下规则时,出现以下错误。

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.

是否可以运行 iptables 具有 root 权限。

Google 救援。

IPTables in docker

Docker runtime privilege

TLDR 版本:

 docker run --privileged

--privileged 标志不再需要。 从 Docker 1.2 开始,您现在可以 运行 使用参数 --cap-add=NET_ADMIN--cap-add=NET_RAW 的图像,这将允许内部 iptables。