解决树莓派docker容器中No access to /dev/mem. Try running as root问题

在树莓派上使用Docker容器运行Python时遇到权限问题,解决方法是在docker run命令中加入--privileged=true参数,同时需下载专用树莓派镜像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:我用docker run启动了一个容器,然后在容器中使用Python时报错,报的是解决python - No access to /dev/mem. Try running as root,原因是容器启动时没有权限。而且我这个容器是运行在树莓派上的,而树莓派通过针脚采集传感器数据时,是需要root权限运行Python代码,所以要想在树莓派上的容器中运行Python代码采集传感器的数据时,需要在docker run -it 中加上--privileged=true。

比如docker run -it --privileged=true 镜像名。

另外也要说一下,在树莓派上运行docker,docker镜像是有区别的,要下载专门的树莓派的docker镜像。

使用docker search rpi-raspbian查找最新的树莓派可运行的镜像。

# Executing docker install script, commit: + sh -c apt-get -qq update >/dev/null + sh -c DEBIAN_FRONTEND=noninteractive apt-get -y -qq install ca-certificates curl >/dev/null + sh -c install -m 0755 -d /etc/apt/keyrings + sh -c curl -fsSL "https://mirrors.aliyun.com/docker-ce/linux/debian/gpg" -o /etc/apt/keyrings/docker.asc + sh -c chmod a+r /etc/apt/keyrings/docker.asc + sh -c echo "deb [arch=armhf signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.aliyun.com/docker-ce/linux/debian bookworm stable" > /etc/apt/sources.list.d/docker.list + sh -c apt-get -qq update >/dev/null + sh -c DEBIAN_FRONTEND=noninteractive apt-get -y -qq install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null + sh -c docker version Client: Docker Engine - Community Version: 28.0.4 API version: 1.48 Go version: go1.23.7 Git commit: b8034c0 Built: Tue Mar 25 15:08:06 2025 OS/Arch: linux/arm Context: default Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ================================================================================ To run Docker as a non-privileged user, consider setting up the Docker daemon in rootless mode for your user: dockerd-rootless-setuptool.sh install Visit https://docs.docker.com/go/rootless/ to learn about rootless mode. To run the Docker daemon as a fully privileged service, but granting non-root users access, refer to https://docs.docker.com/go/daemon-access/ WARNING: Access to the remote API on a privileged Docker daemon is equivalent to root access on the host. Refer to the 'Docker daemon attack surface' documentation for details: https://docs.docker.com/go/attack-surface/这个问题怎么解决
03-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值