首页 > 解决方案 > 如何从 Beaglebone black 上的 docker 容器运行 config-pin?

问题描述

我正在对接我的 beaglebone sw。我几乎已经完成了这个过程,但还有一件事我无法运行。

我使用FROM balenalib/beaglebone-black-alpine-node:12图像。

在操作 CANbus 之前,我必须发出以下命令:

config-pin p9.19 can
config-pin p9.20 can
/sbin/ip link set can1 up type can bitrate 250000

关键是 config-pin 在容器之外。

实现这一目标的最佳解决方案是什么?

标签: node.jsdockerbeagleboneblackcan-bus

解决方案


我猜是config-pinuseglibc而不是muslcwhich 意味着它不能在alpine.

所以建议的解决方案是:

  • 在主机中编写守护程序服务

    这个守护进程从你的 alpine 容器接收命令,然后依赖接收到的命令调用config-pin主机来配置你的beaglebone.

  • 另外,还有一种非常hacky的方法可以让你执行主机的程序:

    注意:它要求您的容器与主机共享所有命名空间,如果您可以接受此限制,您可以尝试一下)

    hacky方式的最小示例:

    1./root/20210903/run.sh主机设置:

    root@shubuntu1:~/20210903# cat /root/20210903/run.sh
    echo "helloworld"
    

    2.运行alpine容器调用run.sh

    root@shubuntu1:~/20210903# docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host balenalib/beaglebone-black-alpine-node:12 /bin/sh
    Here are a few details about this Docker image (For more information please visit https://www.balena.io/docs/reference/base-images/base-images/):
    Architecture: ARM v7
    OS: Alpine Linux 3.12
    Variant: run variant
    Default variable(s): UDEV=off
    The following software stack is preinstalled:
    Node.js v12.19.1, Yarn v1.22.4
    Extra features:
    - Easy way to install packages with `install_packages <package-name>` command
    - Run anywhere with cross-build feature  (for ARM only)
    - Keep the container idling with `balena-idle` command
    - Show base image details with `balena-info` command
    / # chroot /host bash /root/20210903/run.sh
    helloworld
    / # cat /etc/issue
    Welcome to Alpine Linux 3.12
    Kernel \r on an \m (\l)
    / # chroot /host cat /etc/issue
    Ubuntu 18.04.1 LTS \n \l
    / #
    

你可以看到# chroot /host bash /root/20210903/run.sh,我们成功地调用了主机上的脚本。但这真的很hacky,仅供您参考。


推荐阅读