在 Docker 容器内访问 raspistill/pi 相机 [英] Access raspistill / pi camera inside a Docker container

查看:29
本文介绍了在 Docker 容器内访问 raspistill/pi 相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Docker 在 Raspberry Pi 3 Model B 上试用我的 Node.js 应用程序,它运行没有任何问题.

I've been trying out my Node.js app on a Raspberry Pi 3 Model B using Docker and it runs without any troubles.

当应用程序依赖项 (raspicam) 需要 raspistill 使用相机拍照时,就会出现问题.Raspberry 正在运行 Debian Stretch,并且 pi 相机已配置和测试.但是通过 Docker 运行应用程序时我无法访问它.

The problem comes when an app dependency (raspicam) requires raspistill to make use of the camera to take a photo. Raspberry is running Debian Stretch and the pi camera is configured and tested. But I cant access it when running the app via Docker.

基本上,我使用此 Dockerfile 在 win10 64 位机器上使用 Docker 桌面构建映像:

Basically, I build the image with Docker Desktop on a win10 64bit machine using this Dockerfile:

FROM arm32v7/node:10.15.1-stretch

ENV PATH /opt/vc/bin:/opt/vc/lib:$PATH

RUN echo "/opt/vc/lib" > /etc/ld.so.conf.d/00-vcms.conf 
    && ldconfig

# Create the app directory
ENV APP_DIR /home/app
RUN mkdir $APP_DIR
WORKDIR $APP_DIR

# Copy both package.json and package-lock.json
COPY package*.json ./

# Install app dependencies
RUN npm install

# Bundle app source
COPY . .

EXPOSE 3000

CMD ["npm", "start"]

然后在树莓派中,如果我拉图像并运行它:

Then in the Raspberry, if I pull the image and run it with:

docker run --privileged --device=/dev/vchiq -p 3000:3000 [my/image:latest]

我明白了:

错误:生成/opt/vc/bin/raspistill ENOENT

Error: spawn /opt/vc/bin/raspistill ENOENT

经过一番研究,我也尝试运行:

After some researching, I also tried running with:

docker run --privileged -v=/opt/vc/bin:/opt/vc/bin --device=/dev/vchiq -p 3000:3000 [my/image:latest]

使用该命令,我得到:

stderr:/opt/vc/bin/raspistill:加载共享库时出错:libmmal_core.so:无法打开共享对象文件:没有那个文件或目录

stderr: /opt/vc/bin/raspistill: error while loading shared libraries: libmmal_core.so: cannot open shared object file: No such file or directory

有人可以分享一些关于我必须对 Dockerfile 进行哪些更改以便我能够从 Docker 容器内部访问 pi 摄像头的想法吗?提前致谢.

Can someone share some thoughts on what changes do I have to make to the Dockerfile so that I'm able to access the pi camera from inside the Docker container? Thanks in advance.

推荐答案

我在尝试使用来自 docker 容器的相机界面时遇到了同样的问题.根据此线程中的建议,我设法使其与以下 dockerfile 一起使用.

I've had the same problem trying to work with camera interface from docker container. With suggestions in this thread I've managed to get it working with the below dockerfile.

FROM node:12.12.0-buster-slim

EXPOSE 3000

ENV PATH="$PATH:/opt/vc/bin"

RUN echo "/opt/vc/lib" > /etc/ld.so.conf.d/00-vcms.conf

COPY "node_modules" "/usr/src/app/node_modules"
COPY "dist" "/usr/src/app"

CMD ldconfig && node /usr/src/app/app.js

这里有3个要点:

  1. /opt/vc/bin 添加到您的 PATH 中,以便您可以在不引用完整路径的情况下调用 raspistill.
  2. /opt/vc/lib 添加到您的配置文件中,以便 raspistill 可以找到它需要的所有依赖项.
  3. 在容器的运行时而不是构建时重新加载配置文件 (ldconfig).
  1. Add /opt/vc/bin to your PATH so that you can call raspistill without referencing the full path.
  2. Add /opt/vc/lib to your config file so that raspistill can find all dependencies it needs.
  3. Reload config file (ldconfig) during container's runtime rather than build-time.

最后一点是 Anton 的解决方案不起作用的主要原因.ldconfig 需要在正在运行的容器中执行,所以要么使用类似的方法,要么使用 entrypoint.sh 文件代替.

The last point is the main reason why Anton's solution didn't work. ldconfig needs to be executed in a running container so either use similar approach to mine or go with entrypoint.sh file instead.

这篇关于在 Docker 容器内访问 raspistill/pi 相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆