简体   繁体   English

没有到 docker 容器内主机的路由

[英]No route to host within docker container

I am running a Debian docker container on a Windows 10 machine which needs to access a particular url on port 9000 ( 164.16.240.30:9000 )我在 Windows 10 机器上运行 Debian docker 容器,它需要访问端口 9000 ( 164.16.240.30:9000 ) 上的特定 url

The host machine can access it fine via the browser, however when I log in to the terminal and run wget 172.17.240.30:9000 I get failed: No route to host .主机可以通过浏览器正常访问它,但是当我登录终端并运行wget 172.17.240.30:9000failed: No route to host

In an attempt to resolve this I added:为了解决这个问题,我补充说:

ports:
  - 9000:9000

to the docker-compose.yml file, however that doesn't seem to have made any difference.到 docker-compose.yml 文件,但这似乎没有任何区别。

In case you can't guess I'm new to this so what would you try next?如果您猜不到我是新手,那么接下来您会尝试什么?

Entire docker-compose.yml file:整个 docker-compose.yml 文件:

version: '3.4'

services:
  tokengeneratorapi:
    network_mode: host
    image: ${DOCKER_REGISTRY}tokengeneratorapi
    build:
      context: .
      dockerfile: TokenGeneratorApi/Dockerfile
    ports:
      - 5000:80
      - 9000
    environment:
      ASPNETCORE_ENVIRONMENT: local
      SSM_PATH: /ic/env1/tokengeneratorapi/
      AWS_ACCESS_KEY_ID: 
      AWS_SECRET_ACCESS_KEY: 

Command I'm running:我正在运行的命令:

docker-compose build --build-arg BRANCH=featuretest --build-arg CHANGE_ID=99 --build-arg CHANGE_TARGET=develop --build-arg SONAR_SERVER=164.16.240.30

It seems it's the container having connectivity issues so your proposed solution is likely to not work, as that is only mapping a host port to a container port (considering your target URL is not the actual host).似乎是容器存在连接问题,因此您提出的解决方案可能不起作用,因为这只是将主机端口映射到容器端口(考虑到您的目标 URL 不是实际主机)。

Check out https://docs.docker.com/compose/compose-file/#network_mode and try setting it to host.查看https://docs.docker.com/compose/compose-file/#network_mode并尝试将其设置为主机。

Your browser has access to 164.16.240.30:9000 , because it is going through proxy (typical enteprise environment), so the proxy has network connectivity to 164.16.240.30 .您的浏览器可以访问164.16.240.30:9000 ,因为它通过代理(典型的企业环境),因此the proxy具有到164.16.240.30网络连接。 It doesn't mean that also your host has the same network connectivity.这并不意味着您的主机也具有相同的网络连接。 Actually, it looks like your host doesn't have that one.实际上,您的主机似乎没有那个。 That is the reason why direct wget from the container or from terminal has error No route to host .这就是为什么从容器或终端直接 wget 出现错误No route to host

Everything must go through the proxy.一切都必须通过代理。 Try to configure proxy properly - linux apps use environment variables http_proxy,https_proxy usually, but apps may have own option to configure proxy, eventualy you may configure it on the source code level.尝试正确配置代理 - Linux 应用程序通常使用环境变量http_proxy,https_proxy ,但应用程序可能有自己的配置代理选项,最终您可以在源代码级别进行配置。 It depends on used app/code.这取决于使用的应用程序/代码。

I think the issue is that you use host mode in your docker compose config file and do you have IPTABLES firewall allowed for the ports in the debian machine?我认为问题在于您在 docker compose 配置文件中使用了主机模式,并且您是否为 debian 机器中的端口允许 IPTABLES 防火墙? How about windows?窗户呢?

network_mode: host 

which actually bypasses the docker bridge completely so the ports section you specify is not applied.它实际上完全绕过了 docker 桥,因此不应用您指定的端口部分。 All the ports will be opened on the host system.所有端口都将在主机系统上打开。 You can check with你可以检查

nestat -tunlp | grep 5000

And you will see that the port 5000 is not open and mapped to the 80 of the docker as you would expect.并且您会看到端口 5000 未打开并映射到 docker 的 80,如您所料。 However ports 80 and 9000 should be open on the debian network but not binded to any docker bridge only to the debian ip.但是端口 80 和 9000 应该在 debian 网络上打开,但不绑定到任何 docker 网桥,只绑定到 debian ip。

From here: https://docs.docker.com/network/host/从这里: https : //docs.docker.com/network/host/

WARNING: Published ports are discarded when using host network mode警告:使用主机网络模式时,已发布的端口将被丢弃

As a solution could be to remove the network_mode line and it will work as expected.解决方案可能是删除 network_mode 行,它会按预期工作。

Your code doesn't allow your container access to 164.16.240.30:9000 .您的代码不允许您的容器访问164.16.240.30:9000 You should wget 164.16.240.30:9000 from the terminal instead of 172.17.240.30:9000 .您应该从终端 wget 164.16.240.30:9000而不是172.17.240.30:9000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM