首页 > 解决方案 > 如何在自定义网络上允许对 Docker 容器的完全入站和出站 Internet 访问?

问题描述

上周这一直让我陷入困境,因为我的 Docker 环境现在不再工作(在服务器地狱和备份配置无法解决问题之后)。

  1. 我在 Docker 中创建了一个自定义网络(“自定义”),其内部 IP 范围为 172.18.0.0/16。
  2. 我所有的 Docker 容器都附加到“自定义”。
  3. 我有一个主机 DNS 服务器,它对本地域和远程都正常运行(首先使用转发)。
  4. 我配置了反向代理,根据 IPtables 是否正确,这些代理可以工作。
  5. 所有 IPtables 配置均已自动生成。我不知道他们是否正确。

我希望能够:

如果有人可以提供帮助,我将不胜感激,因为我以前做过这个工作,但我看不到我可能设置错误的地方!

IPTables 如下:

#FILTER TABLE

Chain INPUT (policy ACCEPT)
target     prot opt source               destination                

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (0 references)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             172.18.0.2           tcp dpt:36330
ACCEPT     tcp  --  anywhere             172.18.0.2           tcp dpt:7396
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:9000
ACCEPT     tcp  --  anywhere             172.18.0.3           tcp dpt:7999
ACCEPT     tcp  --  anywhere             172.18.0.3           tcp dpt:7990

Chain DOCKER-ISOLATION-STAGE-1 (0 references)
target     prot opt source               destination         
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-ISOLATION-STAGE-2 (2 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-USER (0 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

#NAT TABLE

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
DEFAULT_OUTPUT  all  --  anywhere             anywhere            

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
DEFAULT_POSTROUTING  all  --  anywhere             anywhere            

Chain DEFAULT_OUTPUT (1 references)
target     prot opt source               destination         
DOCKER     all  --  anywhere            !127.0.0.0/8          ADDRTYPE match dst-type LOCAL

Chain DEFAULT_POSTROUTING (1 references)
target     prot opt source               destination         
MASQUERADE  all  --  172.18.0.0/16        anywhere            
MASQUERADE  all  --  172.17.0.0/16        anywhere            
MASQUERADE  tcp  --  172.18.0.2           172.18.0.2           tcp dpt:36330
MASQUERADE  tcp  --  172.18.0.2           172.18.0.2           tcp dpt:7396
MASQUERADE  tcp  --  172.17.0.2           172.17.0.2           tcp dpt:9000
MASQUERADE  tcp  --  172.18.0.3           172.18.0.3           tcp dpt:7999
MASQUERADE  tcp  --  172.18.0.3           172.18.0.3           tcp dpt:7990

Chain DOCKER (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            
DNAT       tcp  --  anywhere             anywhere             tcp dpt:36330 to:172.18.0.2:36330
DNAT       tcp  --  anywhere             anywhere             tcp dpt:7396 to:172.18.0.2:7396
DNAT       tcp  --  anywhere             anywhere             tcp dpt:9000 to:172.17.0.2:9000
DNAT       tcp  --  anywhere             anywhere             tcp dpt:7999 to:172.18.0.3:7999
DNAT       tcp  --  anywhere             anywhere             tcp dpt:7990 to:172.18.0.3:7990

标签: dockerdnssynology

解决方案


最后,我炸毁了整个服务器并从头开始,还有一些备份。我认为整个配置都是出乎意料的。


推荐阅读