Docker 错误:无法访问/dev/mem.尝试以 root 身份运行 [英] Docker error : No access to /dev/mem. Try running as root

查看:22
本文介绍了Docker 错误:无法访问/dev/mem.尝试以 root 身份运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 raspberry pi,并且在其中安装了 docker.我制作了一个 python 脚本来读取其中的 gpio 状态.所以当我运行下面的命令时

I have a raspberry pi and I have installed dockers in it. I have made a python script to read gpio status in it. So when I run the below command

sudo docker run -it --device /dev/gpiomem app-image

它运行完美并显示 gpio 状态.现在我已经创建了一个 docker-compose.yml 文件,因为我想将此 app.py 部署到我创建的 swarm 集群.

It runs perfectly and shows the gpio status. Now I have created a docker-compose.yml file as I want to deploy this app.py to the swarm cluster which I have created.

以下是docker-compose.yml

version: "3"
services:
    app:
        image: app-image
        deploy:
            mode: global
        restart: always
        privileged: true

当我使用 sudo docker stack deploy 命令开始部署时,映像已部署,但出现错误:

When I start the deployment using sudo docker stack deploy command, the image is deployed but it gives error:

No access to /dev/mem. Try running as root

所以它说它无权访问/dev/mem,但是这在我使用device时很奇怪,为什么该服务无权访问.它还说尝试以 root 身份运行,我认为所有容器都已经在 root 中了.我还尝试通过在代码中包含命令 chmod 777/dev/gpiomem 来授予该文件的完整权限,但它仍然显示此错误.

So it says that it do not have access to /dev/mem, but this is very strange when I am using device, why the service do not have access. It also says trying running as root which I think all the containers are in root already. I also tried giving the full permissions to the file by including the command chmod 777 /dev/gpiomem in the code but it still shows this error.

我的主要问题是,当它使用 docker run.. 命令正常运行时,为什么在使用 sudo docker 部署时在 docker-compose 文件中显示错误堆栈部署.?如何解决这个问题.?

My main question is that when it runs normally using docker run.. command why it is showing error in docker-compose file when deploying using sudo docker stack deploy.? How to resolve this issue.?

谢谢

推荐答案

swarm 模式不支持添加设备、功能和使用特权模式.yml 文件中的这些选项用于使用 docker-compose 而不是 docker stack deploy.您可以在 github issue #24862 中跟踪将这些功能添加到群模式的进度.

Adding devices, capabilities, and using privileged mode are not supported in swarm mode. Those options in the yml file exist for using docker-compose instead of docker stack deploy. You can track the progress on getting these features added to swarm mode in github issue #24862.

由于您需要做的就是访问设备,因此您可能很幸运地将设备的文件添加为卷,但这是在黑暗中进行的:

Since all you need to do is access a device, you may have luck adding the file for the device as a volume, but that's a shot in the dark:

volumes:
- /dev/gpiomem:/dev/gpiomem

这篇关于Docker 错误:无法访问/dev/mem.尝试以 root 身份运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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