啟動容器時增加參數
方法一:完全開放
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.jfrwli.cn/article/130627.html
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!