I have two docker container.
One is the "backend", the other "connector"..
The connector needs to have its network type set to "host" (To receive udp multicast: ssdp/mdns packets).
But it also needs to be able to use docker dns system so i can resolve container names to their ip addresses.
How can i do this?
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
ports:
- "8080:8080"
depends_on:
- database
tty: true
connector:
image: "project/connector:latest"
container_name: connector
hostname: connector
ports:
- "1900:1900/udp"
environment:
- NODE_ENV=production
- BACKEND_HOST=backend
depends_on:
- backend
network_mode: host
tty: true
When i run it with docker compose up
, my connector container throws a "EAI_AGAIN" error:
connector | Error: getaddrinfo EAI_AGAIN backend
connector | at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26) {
connector | errno: -3001,
connector | code: 'EAI_AGAIN',
connector | syscall: 'getaddrinfo',
connector | hostname: 'backend'
connector | }
Which means the node.js app cant resolve the hostname "backend". Which is not a surprise since the network is set to "host".
How can have the "connector" container have its network set to "host" but is still able to resolve other container names?