0

Is there a way to expose Bluetooth to a container in Docker Swarm mode?

I see that people usually use --net=host with docker but the Docker Compose's equivalent of network_mode: host is ignored by swarm.

I've also seen suggestions to use local host network, like below:

networks:
  host:
    name: host
    external: true

Unfortunately, I still need to access some other networks with database and Traefik's proxy and accessing host network requires not to use any other network or it ends up in an error

container sharing network namespace with another container or host cannot be connected to any other network

I wonder if there's any other way of exposing BT to the container? Just to mention, it's on Raspberry Pi 4, so BT isn't provided by a separate USB dongle

TeoTN
  • 515
  • 1
  • 7
  • 22

1 Answers1

-1

"Is there a way to expose Bluetooth to a container in Docker Swarm mode?"

If the bluetooth device in question has a network port opened on the host, and the container is managed via docker swarm, the following snippets may help. Managing bluetooth device vs accessing bluetooth service (eg. ftp etc) are not the same thing.

"need to access some other networks with database and Traefik's proxy"

To access other services on other network you can add those at top level networks section and specify them in the services networks section:

networks:
  database_network
    name: database_network
    external: true
  proxy_network
    name: proxy_network
    external: true
  ...

services:
  svc_name:
    image: ...
    networks:
      - database_network
      - proxy_network

"and accessing host network requires not to use any other network or it ends up in an error""

The port needs to have the mode set to 'host' instead:

ports:
  - published: 9888
    target: 80
    mode: host  # set the mode

However, since containers can access network service thru port (ie. created by bluetooth app running on host), it is not necessary for the container to run in host network.

gohm'c
  • 13,492
  • 1
  • 9
  • 16
  • Hey, thanks for the reply but I think this doesn't relate to my question, I'm asking about accessing host devices like Bluetooth or GPIO, not about accessing services in other network nor exposing ports – TeoTN Jan 13 '21 at 23:50
  • answer is based on "...need to access some other networks with database and Traefik's proxy and accessing host network..." and the error message in your question. If this is about bluetooth device, here's a good one to follow: https://stackoverflow.com/questions/28868393/accessing-bluetooth-dongle-from-inside-docker – gohm'c Jan 15 '21 at 01:35