Sending can messages to docker swarm

Hello!
I previously had a project using just a docker container (also did it in compose), where I had a script running in my terminal , it was a python script that wrote can messages and sent it to the buses vcan0, vcan1, etc… this was with the can library, it was like
can.bus(interface="socketcan", channel = "vcan0", receive_owm_messages=True)

For the docker containers/compose what I did was used network=host, and that made it that my containers also got these messages, so basically if I did ifconfig -a | grep can in my container and outside my container I got my virtual buses set up on both.

I want to now move to docker swarm but I am not finding any way to do this, they recommended me to use EBPF but honestly I am finding it quite difficult and confusing to implement.

Does someone know how could I handle this communication from my host to my container please :frowning:

I am using ubuntu 20:04.

Is your can bus on host a Linux socket? Regular sockets like the Docker socket can be bind mounted into Swarm service containers.

It’s done a lot with Traefik:

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

this is my python file:
import can
import time

data = “04 1B 13 08 04 25 64 68”.split(" ") # send date & time

msg =
for i in data:
msg.append(int(i, 16))

bus = can.Bus(interface=‘socketcan’,
channel=“vcan0”,
receive_own_messages=True)

bus_2 = can.Bus(interface=‘socketcan’,
channel=“vcan1”,
receive_own_messages=True)

message = can.Message(arbitration_id = 0x06FEE61C, is_extended_id = True,
data = msg)

message_2 = can.Message(arbitration_id = 0x06FEE61C, is_extended_id = True, data = [1])

while True:
bus.send(message, timeout=0.5)
bus_2.send(message_2, timeout=0.5)
print("Send: ", data)
time.sleep(1)

the virtual can buses are set on my Linux machine.

I could get traefik now, but I was wondering how do I instruct my can to be sent to the volume? And if I have to add something else for traeffik to work or I just have to add that volume line in my stack.yaml? thanks!

Hi i am sorry to ask again, I added the volumes in my .yaml file to deploy like this but I keep getting the same error where there are no virtual can buses set up in my docker container node:
version: ‘3’

services:
  reverse-proxy:
  # The official v2 Traefik docker image
    image: traefik:v2.10
    # Enables the web UI and tells Traefik to listen to docker
    command: --api.insecure=true --providers.docker
    ports:
    # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    # So that Traefik can listen to the Docker events
    #

  can_bus:
    image: docker.deere.com/can_bus:network
    ports:
      - "8000:3000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Sorry, you misunderstood. I was asking if can was using a regular Linux socket. I don’t know.

A regular Linux socket, like Docker socket, can be used inside the container by using a bind mount.

ChatGPT thinks it’s not a regular socket, so you would need network: host or privileged, which both is not available in Swarm.

(“Is socketcan using a regular Linux socket, which can be bind mounted into a Docker container, like the Docker socket?”)