早上好。 我运行Ubuntu 14.04服务器和Docker 1.8.1,UFW是我pipe理iptables的前端。
我需要运行一个应用程序到一个容器中。 我确实需要以下行为:
/etc/default/docker DOCKER_OPTS="--iptables=false"设置了DOCKER_OPTS="--iptables=false" 。 这样做,docker现在应该跳过设置任何 iptables规则。 然后,我在UFW中做了以下工作,以便将docker集装箱连接到外部世界:
/etc/default/ufw设置DEFAULT_FORWARD_POLICY="ACCEPT" /etc/sysctl.conf设置net.ipv4.ip_forward=1和net.ipv4.conf.all.forwarding=1 我还将以下行添加到/etc/ufw/before.rules以启用NATfunction:
# nat Table rules *nat :POSTROUTING ACCEPT [0:0] # Forward traffic from private network through eth0, the Internet iface on master. -A POSTROUTING -s 172.17.42.1/16 -o eth0 -j MASQUERADE # don't delete the 'COMMIT' line or these nat table rules won't be processed COMMIT
其中172.17.42.1/16是docker服务器的IP范围。
重启后,我已经运行sudo iptables -t nat -L -n ,这给了我:
[....] Chain POSTROUTING (policy ACCEPT) target prot opt source destination MASQUERADE all -- 172.17.0.0/16 0.0.0.0/0
然后,因为我的DEFAULT_OUTPUT_POLICY被设置为DROP ,并且我想testingiptables=false选项是否真正起作用,所以我跑了:
docker run -it ubuntu:14.04 bash root@56997560933c:/# apt-get update
但是..容器能够下载更新,即使端口80 / tcp和53在主机上没有打开到外面。
我知道想知道…我做错了什么? 为了避免Docker容器使用我在iptables(使用UFW)中不允许的端口连接到外部世界,我还需要做些什么?
谢谢。
注意完整性:在我的iptables的任何链中都没有DOCKER的痕迹。 此外,下载更新时,如果我运行netstat ,没有build立连接之外的SSH …这是更奇怪的…
从另一个用户的这个问题报道,发布在stackoverflow上。 我认为这是正确的地方。