2

I have 3 services defined in docker-compose. One of them sends a multicast that should be received by the other 2 services, but only one of them receives it. The 2 receivers are in different networks, and the sender is part of both networks.

docker-compose.yml:

services:
  sender:
    networks:
      - network_a
      - network_b

  receiver1:
    networks:
      - network_a
    depends_on:
      - sender

  receiver2:
    networks:
      - network_b
    depends_on:
      - sender

networks:
  network_a:
    ipam:
      driver: default
      config:
      - subnet: 172.20.1.0/24
        gateway: 172.20.1.1

  network_b:
    ipam:
      driver: default
      config:
      - subnet: 172.20.2.0/24
        gateway: 172.20.2.1

receiver1 gets the multicast but receiver2 doesn't.

If I remove network_a from sender networks field, then receiver2 receives the message. Somehow multicast doesn't work on multiple networks.

Does anyone know why this happens?

timeFly
  • 123
  • 11
  • 1
    have a look here: https://github.com/docker/docker/issues/23659 Quoted from there: "If you do not bind a local interface address to the multicast sender socket, Linux (afaik) will select your default routes interface address." – CFrei Jul 19 '16 at 13:27
  • @CFrei Thank you, you were right, that was the path to the solution. – timeFly Jul 26 '16 at 12:30

1 Answers1

1

I'm going to answer myself as I found out what was the problem.

The problem isn't with Docker or anything related to Docker, it's strictly a multicast issue.

Basically, multicast works only in one network and if you want to send a multicast message in multiple networks you have to iterate through all the networks interfaces to be used.

For example, in Java, you would have to call setInterface() method before sending the multicast message to specify exactly the used network. https://docs.oracle.com/javase/7/docs/api/java/net/MulticastSocket.html#setInterface(java.net.InetAddress)

timeFly
  • 123
  • 11