如何让CAN总线在docker容器内运行?

问题描述 投票:0回答:3

我成功地对在 Beaglebone black 上运行的 Nodejs 应用程序进行了 docker 化。但现在我想从 docker 容器内访问 CAN,但它不起作用。

请注意,我成功在主机中配置了 CAN 端口,并且 candump 显示它可以工作。

$ candump can1
  can1  18FF30D0   [8]  00 00 00 00 00 00 00 00
  can1  18FF02D0   [4]  00 00 00 00
  can1  18FF21D0   [3]  00 00 00
  can1  18FF3CD0   [4]  00 7D 28 7D
  can1  18FF30D0   [8]  00 03 00 00 00 00 00 00
  can1  18FF02D0   [4]  00 00 00 00

我在 Dockerfile 中构建了 socketcan 节点模块,如下所示:

 #If you don't have node/npm already, add that first
RUN apk add --no-cache nodejs

# Add the necessary build and runtime dependencies (see https://stackoverflow.com/questions/36202095/node-serialport-failing-on-alpine-linux)
RUN apk add --no-cache make gcc g++ python3 linux-headers udev

#RUN apk add --no-cache --virtual .gyp python3 make g++
RUN  npm install 

从容器运行我的应用程序后,我收到以下异常:

 -- 🟡- 🚎 Canbus:can0: switched to channel "can0"…
Pepsr v2.1.192 5:36:40 PM 📈 [pepsr-iingenierie]  -- 🟡- 🚎 Canbus:can0: cancel CAN as other channel "can0" doesn’t work either
Pepsr v2.1.192 5:36:40 PM 📈 [pepsr-iingenierie]  -- 🔴- 🚎 Canbus:can0: Error: Error while creating channel
    at Object.exports.createRawChannel (/home/debian/Desktop/devel/iot/node_modules/socketcan/socketcan.js:38:12)
    at Canbus._connect (/home/debian/Desktop/devel/iot/pepsr.ddk.protocol.canBus.js:308:34)
    at Canbus.connect (/home/debian/Desktop/devel/iot/pepsr.module.js:272:9)
    at Object.<anonymous> (/home/debian/Desktop/devel/iot/pepsr.js:608:20)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 
node.js docker beagleboneblack can-bus
3个回答
4
投票

感谢帮助我找到解决方案的贡献者。

我终于发现,让容器访问主机CAN总线最简单的方法就是使用

--network
参数,如下:

$ docker run --rm --network=host <your image>

1
投票

将网络接口转发到 Docker 或多或少描述如下:与 docker 容器共享虚拟网络


0
投票

当我运行 docker run 时,我已经传递了 --network 主机参数,但我仍然没有在容器中看到 can 网络,即使它在主机上可见。我在 raspi 5 上运行这个

© www.soinside.com 2019 - 2024. All rights reserved.