Unable to connect service to host network and other services


#1

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!


#4

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?


#5

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.


#6

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