簡體   English   中英

如何使用iptables保護docker容器

[英]how to secure docker containers with iptables

我正在嘗試保護容器免受外部IP訪問“ 0.0.0.0”

我想配置一些容器以供公共訪問,而另一些則限制為某些IP。

sudo iptables -N DOCKER-USER
sudo iptables -I DOCKER-USER -j DROP

# where x.x.x.x is external IP allowed
sudo iptables -I DOCKER-USER -s x.x.x.x -j ACCEPT

# where yyyy is the external port that will be allow
sudo iptables -I DOCKER-USER -p tcp --dport yyyy -j ACCEPT

sudo iptables -I FORWARD -o docker0 -j DOCKER-USER

它可以正常工作,但是重新啟動后,此配置將被重置並停止工作。

我已經嘗試將該腳本放在/etc/rc.local中,但是重啟后不會執行。

我的環境是:

Client:
 Version:      17.05.0-ce
 API version:  1.29
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Thu May  4 22:10:54 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.05.0-ce
 API version:  1.29 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Thu May  4 22:10:54 2017
 OS/Arch:      linux/amd64
 Experimental: false

您可以保存當前的iptables配置,然后在服務器啟動時加載它:

iptables-save | sudo tee /etc/iptables.conf

將以下內容復制到/etc/rc.local

# Load iptables rules from this file
iptables-restore < /etc/iptables.conf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM