Docker – 从容器中为主机修改IPTABLES
我想运行一个中央日志和fail2ban
服务的docker容器来防止dos / ddos攻击。
我有一个问题,运行一个容器,这样的能力,它也可以修改主机的iptables。
有一个项目ianblenke / docker-fail2ban,但它不工作…
给容器标志特权只允许我在这个容器上控制iptables
。 有没有办法通过容器控制主机iptables
?
问候。
默认情况下,Docker容器在隔离的networking名称空间内运行,在这个名称空间中,他们无法访问主机networkingconfiguration(包括iptables)。
如果您希望您的容器能够修改主机的networkingconfiguration,则需要将--net=host
选项传递给--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
来运行。
--privileged
标志不再需要。 从Docker 1.2开始,您现在可以使用参数--cap-add=NET_ADMIN
和--cap-add=NET_RAW
来运行映像,这将允许内部iptables。
也许值得注意的是,在Docker Hub的官方Ubuntu镜像中没有安装iptables
包。 所以一般的指导应该是
-
apt-get install iptables
- 使用
--net=host
和--cap-add=NET_ADMIN
运行--net=host
容器--cap-add=NET_RAW
选项。
另外,如果你有一个缺lessiptables
包的docker镜像,并且你不想从它创build一个自定义镜像,你可以在同一个networking空间里运行iptables
容器。 例如,如果您有容器container-without-iptables
正在运行,并且您想在同一个networking命名空间中启动一些container-with-iptables
,那么可以这样做:
docker run -it --pid=container:container-without-iptables --net=container:container-without-iptables --cap-add sys_admin container-with-iptables
- Docker,不能在Ubuntu 14.04上使用rhel / centos容器
- 是可以使用.dockerignore使docker构build真的忽略了一切?
- 与尤里卡服务器和docker的spring启动应用程序
- docker nginx连接被拒绝,同时连接到上游
- Kubernetes私人dockerregistry推送错误
- 如何docker exec -ti CONTAINER_NAME / bin / bash在部署的docker栈上?
- 如何将docker集装箱的以太网接口的stream量转移到桥梁?
- 错误:在RedHat 6.8上运行dockerfile或创build容器时,设备或资源繁忙
- 500(内部服务器错误)与Laravel和Docker