Docker容器没有互联网:网络主机或ISP问题

问题描述

我需要帮助,以找到在Docker容器中访问Internet的方法

几天前,我更换了ISP,此后,当我“组成”我的项目的微服务时,没有一个容器可以访问Internet。

经过多次尝试,我尝试了以下方法

--net = host (in the docker run)
--network = host (when I build the image)
network_mode = "host" (in the docker-compose)

最后,我可以从容器访问Internet,但是现在我无法访问服务的网址。

任何建议...

解决方法

好吧,我联系我的ISP来解决我的docker容器的连接问题,他们向我解释说它们不支持它们。 答案:更改ISP。

,

这只是RHEL linux上的快速修复(不是最安全的解决方案),用于允许容器访问外部资源(泊坞窗基础设施外部)来设置冷杉墙。

Path.GetDirectoryName

要在docker主机(服务器正在运行的容器)外部公开应用程序,必须在docker-compose.yml文件中指定“公开端口”

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --permanent --zone=trusted --add-interface=docker0
firewall-cmd --permanent --zone=trusted --add-interface=docker_gwbridge
firewall-cmd --reload

或使用命令行命令:

services:
  whoami-test:
    image: containous/whoami
    ports:
      # first is docker host listening port
      # second is docker container exposed port
      - 80:8080 
....

以上内容很大程度上取决于您的服务器/泊坞窗/容器配置,因此请请勿复制粘贴