我想运行一个带有中央日志和fail2ban服务的docker容器,以防止dos/ddos攻击。
我在运行一个容器时遇到了一个问题,这个容器的功能可能还会修改主机的iptables。
有一个项目ianblenke/docker-fail2ban,但是它不工作...
赋予容器标志特权只允许我控制这个容器上的iptables。有没有办法通过容器控制主机iptables?
致以问候。
发布于 2015-05-11 21:55:11
默认情况下,Docker容器在隔离的网络命名空间内运行,在该命名空间中,它们无权访问主机网络配置(包括iptables)。
如果您希望您的容器能够修改主机的网络配置,则需要将--net=host选项传递给docker run。从docker-run(1)手册页:
--net="bridge"
Set the Network mode for the container
'bridge': creates a new network stack for the container on the docker bridge
'none': no networking for this container
'container:': reuses another container network stack
'host': use the host network stack inside the container.
Note: the host mode gives the container full access to
local system services such as D-bus and is therefore
considered insecure.您需要同时使用--privileged和--net=host运行。
发布于 2017-06-13 22:04:29
不再需要--privileged标志。从Docker1.2开始,您现在可以使用参数--cap-add=NET_ADMIN和--cap-add=NET_RAW运行您的镜像,这将允许内部iptables。
同样值得注意的是,在Docker Hub的官方Ubuntu镜像中,没有安装iptables包。所以一般的指令应该是
带有--net=host和--cap-add=NET_ADMIN --cap-add=NET_RAW选项的
apt-get install iptables此外,如果您有一个缺少iptables包的docker镜像,并且您不想从它创建自定义镜像,那么您可以在同一网络空间中运行带有iptables的容器。例如,如果您正在运行容器container-without-iptables,并且您想要在同一网络名称空间中启动一些container-with-iptables,您可以这样做:
docker run -it --pid=container:container-without-iptables --net=container:container-without-iptables --cap-add sys_admin container-with-iptableshttps://stackoverflow.com/questions/30169013
复制相似问题