Multi network container / ssdp/mdns traffic from host network - dns issue

I have two container that needs to communicate with each other.
One of the containers needs to be on the host network to send&receive udp multicast packages.

How can i do this with docker compose?

I got it working when i deploy the container per hand and use the container IPs.
But thats not suitable and feels like there must be a better way.

I want that the container that has its network type set to “host”, but its still possible to resolve other docker container names like they are on the same bridge network.

version: "2"

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

    image: "project/backend:latest"
    container_name: backend
    hostname: backend
      - NODE_ENV=production
      - DATABASE_HOST=database
      - "8080:8080"
      - database
    tty: true

    image: "project/connector:latest"
    container_name: connector
    hostname: connector
      - NODE_ENV=production
      - BACKEND_HOST=backend
      - backend
    #    net: host
    network_mode: "host"
    tty: true

The problem with the yaml file above is, that the connector can not resolve “backend”.

When a container uses the host network, it means you don’t have network isolation and you don’ use any of the Docker networks. It also means the DNS configuration, and host name resolution comes from the host. You can connect to the forwarded port of the backend on localhost. If that port is not 8080 (which is already forwarded) or you need to forward another. if you don’t want that port to be accessible remotely, just forward the port only from the loopback IP address:

      - ""

I used 8081 as an example. Use the port that you need.