Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

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.

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.

In case you can't guess I'm new to this so what would you try next?

Entire docker-compose.yml file:

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
like image 235
m.edmondson Avatar asked Mar 07 '20 18:03

m.edmondson


People also ask

What is host network mode in Docker?

Docker network host, also known as Docker host networking, is a networking mode in which a Docker container shares its network namespace with the host machine. To access the application inside the container, use the port at the host's IP address (e.g., port 80).


1 Answers

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).

Check out https://docs.docker.com/compose/compose-file/#network_mode and try setting it to host.

like image 158
agermain Avatar answered Sep 27 '22 16:09

agermain