docker 容器防火墙设置

docker 容器防火墙设置
启动容器时增加参数
方法一:完全开放
--privileged=true
1
但是这样的话就将系统的所有能力都开放给了docker容器
有一个image为aaa的将启动为容器名为bbb的且在容器内需要使用iptables功能,可以使用–privileged=true来进行开启,如:

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

例如:

docker run -it --privileged=true -d -p 192.168.55.90:8000:8000/tcp  --name my_centos centos /bin/bash


1
方法二:部分开放
对于iptables需要的权限进行开放,其它的权限不予开放
--cap-add NET_ADMIN --cap-add NET_RAW
1
操作实例(桥接模式配置容器防火墙):
#生成容器
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 /]#

---------------------
作者:xycoder
来源:CSDN
原文:https://blog.csdn.net/u011704394/article/details/54599727
版权声明:本文为博主原创文章,转载请附上博文链接!

posted on 2019-03-24 14:47  PerfectData  阅读(1949)  评论(0编辑  收藏  举报

导航