docker 详解设置容器防火墙

2025-05-27 0 92

docker 容器防火墙设置

启动容器时增加参数

方法一:完全开放

?

1
--privileged=true

但是这样的话就将系统的所有能力都开放给了Docker容器

有一个image为aaa的将启动为容器名为bbb的且在容器内需要使用iptables功能,可以使用–privileged=true来进行开启,如:

?

1
docker run --privileged=true -d -p 4489:4489/tcp --name bbb aaa

方法二:部分开放

对于iptables需要的权限进行开放,其它的权限不予开放

?

1
--cap-add NET_ADMIN --cap-add NET_RAW

操作实例(桥接模式配置容器防火墙):

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22
#生成容器

docker run -itd --net=none --name=centos06 --cpuset-cpus="0-3" -m 1024M --memory-reservation 1024M --cap-add NET_ADMIN --cap-add NET_RAW ssh-java1.8-tomcat8-centos6 /bin/bash

#配置网络IP

pipework br0 centos06 132.97.8.6/24@132.97.8.1

#进入容器

docker attach centos06

#设置容器的防火墙

[root@dee8225a9bba /]# iptables -A INPUT -s 132.97.0.0/16 -p tcp -m tcp --dport 21 -j ACCEPT

[root@dee8225a9bba /]# iptables -A INPUT -s 132.97.0.0/16 -p tcp -m tcp --dport 22 -j ACCEPT

[root@dee8225a9bba /]# iptables -A INPUT -s 132.97.0.0/16 -p tcp -m tcp --dport 8080 -j ACCEPT

[root@dee8225a9bba /]# iptables -A INPUT -j DROP

[root@dee8225a9bba /]# service iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

[root@dee8225a9bba /]# service iptablse restart

iptablse: unrecognized service

[root@dee8225a9bba /]# service iptables restart

iptables: Setting chains to policy ACCEPT: mangle nat filte[ OK ]

iptables: Flushing firewall rules: [ OK ]

iptables: Unloading modules: iptable_mangle iptable_nat ip[FAILED]lter iptable_mangle iptable_nat iptable_filter ip_tables

iptables: Applying firewall rules: [ OK ]

[root@dee8225a9bba /]#

参考:http://www.zzvips.com/article/130627.html

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 行业资讯 docker 详解设置容器防火墙 https://www.kuaiidc.com/68327.html

相关文章

发表评论
暂无评论