0

I need to resolve a container name to the IP Address from the docker host.

The reason for this is, i need a container to run on the host network, but it must be also able to resolve the container "backend" which it connects also to. (The container must be send & receive multicast packets)

docker-compose.yml

version: "3"
services:

  database:
    image: mongo
    container_name: database
    hostname: database
    ports:
      - "27017:27017"

  backend:
    image: "project/backend:latest"
    container_name: backend
    hostname: backend
    environment:
      - NODE_ENV=production
      - DATABASE_HOST=database
      - UUID=5025f846-7587-11ed-9ca7-8b992b5e7dd3
    ports:
      - "8080:8080"
    depends_on:
      - database
    tty: true

  frontend:
    image: "project/frontend:latest"
    container_name: frontend
    hostname: frontend
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      - backend
    environment:
      - BACKEND_HOST=backend
  connector:
    image: "project/connector:latest"
    container_name: connector
    hostname: connector
    ports:
      - "1900:1900/udp"
    #expose:
    #  - "1900/udp"
    environment:
      - NODE_ENV=production
      - BACKEND_HOST=backend
      - STARTUP_DELAY=1500
    depends_on:
      - backend
    network_mode: host
    tty: true

How can i resolve the hostname "backend" via docker from the docker host?

dig backend @127.0.0.11 & dig backend @172.17.0.1 did not work.

A test with a docker ubuntu image & socat proves, that i can receive ssdp multicast packets:

docker run --net host -it --rm ubuntu
socat UDP4-RECVFROM:1900,ip-add-membership=239.255.255.250:0.0.0.0,fork -

The only problem i now have is the DNS/Container name resolution from the host (network).

TL;DR
The container "connector" must be on the host network,but also be able to resolve the container name "backend" to the docker internal IP Address.

NOTE: Perhaps this is better suited on superuser or similar?

Marc
  • 2,920
  • 3
  • 14
  • 30
  • Since the container is running on the host network and it's completely disabled Docker's networking layer, for networking purposes it's indistinguishable from a non-container process running on the same host, and the techniques in [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) should work. – David Maze Dec 28 '22 at 12:52
  • @DavidMaze Thats not what i need. The container needs be able to receive and send multicast packets on the host network, but connects at the same time to the backend, and not connect on a service on the docker host. Perhaps i did not fully understand what you said. – Marc Dec 28 '22 at 13:34
  • 1
    A container is either in the Docker network system, or uses the host network; it can't do both. If it's on the host network then it behaves like a non-container process from a networking point of view. If the host-network container needs to connect to other containers then it needs to go through the published `ports:`. Also see [How to use the host network, and any other user-defined network together in Docker-Compose?](https://stackoverflow.com/questions/47303141/how-to-use-the-host-network-and-any-other-user-defined-network-together-in-dock) – David Maze Dec 28 '22 at 14:20
  • @DavidMaze Nice! Thank you very much. That works in a way im ok with. Docker and Networking is something special ;) – Marc Dec 28 '22 at 14:44

0 Answers0