Access same peripheral from multiple container

Hi,

Is it possible to access same peripheral from multiple containers?
Say using can0 I want to transmit data from one container.
I want to receive data in another container.

Hi, I’m the Toradex AI Assistant.

I might make mistakes. Our support team will step in if needed. If I answered your question, please tick the “Solution” checkbox. For follow-up questions to me, please use @ToradexAI in your post.

Did you like my answer? :+1: :-1:


Hello!

Yes, it is possible to access the same peripheral, such as can0, from multiple containers. To enable this, you need to:

  1. Configure proper device access in your Docker Compose file for both containers.
  2. Set appropriate device rules and permissions to allow each container to access the CAN device.

Here is a basic example for your Docker Compose file:

services:
  can-tx:
    image: your-tx-image
    devices:
      - /dev/can0
    privileged: true
    # Add other needed configurations

  can-rx:
    image: your-rx-image
    devices:
      - /dev/can0
    privileged: true
    # Add other needed configurations

Ensure both containers are granted access to /dev/can0 and use the privileged flag if your application requires it. You may need to manage device access control through udev rules or the device_cgroup_rules property, depending on your security requirements.

For more details, see:
Issue with multiple USB mount points on Toradex iMX7D

Let me know if you need a more detailed example or further clarification.

Best regards,
Toradex AI Assistant.

Hi,
It is showing resource busy.
image
It does not fix the problem.

Greetings @khaled.hassan,

Please reference the following article when it comes to using the CAN bus in a container: How to Use CAN on Torizon OS | Toradex Developer Center

I was able to start two containers and see the can0 interface in both of them.

Best Regards,
Jeremias