Unable to connect service to host network and other services

Hi,

We got two services that communicate with each other in the default network using the following docker-compose file:

version: '2'

services:
  redis:
    image: redis
    ports:
      - "6379:6379"  
    
  manager:
    build: ./manager/
    privileged: true
    depends_on:
      - redis

These services are both inside the xxx_default bridge network created by docker-compose, where xxx is the resin application id.

This setup works fine, until my manager service needs access to the mac address of the host OS.
If we add network_mode: "host" to the service it is unable to connect to other services since they are no longer in the same network: redis is in the xxx_default network and manager is in the host network.

Thus the manager service should be in the host network while also being able to connect to the other services.
Here is what we tried to achieve this:

version: '2'

networks:
  to_host:
    driver: host
  internal:
    driver: bridge

services:
  redis:
    image: redis
    networks:
     - internal
    ports:
      - "6379:6379"  
  manager:
    build: ./manager/
    networks:
      - to_host
      - internal
    privileged: true
    depends_on:
      - redis

This didn’t work since the networks created by balena were all bridge networks:

root@c258114:~# balena network ls
NETWORK ID          NAME                DRIVER              SCOPE
2291902e710d        xxx_default         bridge              local
7ec45f1e094a        xxx_internal        bridge              local
199f4fa16bae        xxx_to_host         bridge              local
022ca1b6853b        bridge              bridge              local
168b6e906fac        host                host                local
331763c499cd        none                null                local
4cf7ede90136        supervisor0         bridge              local

Then we tried to specify the host network created by balena as an external network, also to no avail:

version: '2'

networks:
  to_host:
    external:
      name: host

services:
  redis:
    image: redis
    ports:
      - "6379:6379"  
    
  manager:
    build: ./manager/
    networks:
      - to_host
    privileged: true
    depends_on:
      - redis

What can we try to achieve this? Is this even possible?
Thanks in advance!

Hi. So the original problem you are trying to solve is how to get the MAC address of some network interface from within the container?

Yes that is the problem we’re trying to solve.

We we’re in contact with support and they mentioned the DBUS API, especially the HwAddress and PermHwAddress properties.
They provided a couple of resources:
A block of code that interacts with the host’s network API from the app container: https://docs.resin.io/reference/OS/network/2.x/#changing-the-network-at-runtime
Docs on the wired network endpoint https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Device.Wired.html
Docs on the wireless network endpoint https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Device.Wireless.html

I think we’ll try to implement this and mark this issue as solved for now.

Great, I was about to suggest the same, didn’t notice the thread duplication :slight_smile:

Hi @ben.clerix
I have stumbled with a similar problem and I was wondering if this yield positive results or if you find another way forward?

Thanks

Hi @mvargasevans

We implemented the DBUS API as mentioned in the solution in this thread.