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

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

问题描述

我有一个树莓派,并且已经在其中安装了dockers。我已经制作了一个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 部署到集群中

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正常运行时。命令为什么在 docker-中显示错误-使用 sudo docker stack deploy 进行部署时组成文件。

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.?

谢谢

推荐答案

如上所述在 docker组成设备


注意:在以
a(版本3)撰写文件以群集模式部署堆栈时,将忽略此选项。

Note: This option is ignored when deploying a stack in swarm mode with a (version 3) Compose file.

在swarm中忽略了devices选项。您可以使用 privileged:true 来访问所有设备。

The devices option is ignored in swarm. You can use privileged: true which will give access to all devices.

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

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