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

查看:108
本文介绍了在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"]

然后在Raspberry中,如果我拉出图像并使用以下命令运行它:

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天全站免登陆