docker - docker 容器中的 root 权限被拒绝

标签 docker ubuntu-20.04

在过去的几天里,我在构建或运行 docker 容器时遇到了一些问题。

root 似乎没有访问文件系统的权限。

例如。我创建了这个非常简单的 Dockerfile

FROM centos

RUN id && ls -l /usr/bin/yum /usr/bin/dnf-3 && yum install mlocate

当我尝试构建图像时出现错误

Step 1/2 : FROM centos
 ---> 470671670cac
Step 2/2 : RUN id && ls -l /usr/bin/yum /usr/bin/dnf-3 && yum install mlocate
 ---> Running in f7b32a009a74
uid=0(root) gid=0(root) groups=0(root)
-rwxr-xr-x 1 root root 1954 Dec 19 15:43 /usr/bin/dnf-3
lrwxrwxrwx 1 root root    5 Dec 19 15:43 /usr/bin/yum -> dnf-3
/usr/libexec/platform-python: can't open file '/usr/bin/yum': [Errno 13] Permission denied
The command '/bin/sh -c id && ls -l /usr/bin/yum /usr/bin/dnf-3 && yum install mlocate' returned a non-zero code: 2

这个问题似乎更普遍,即使在 ubuntu 或 alpine 上我也会遇到类似的错误,所以我怀疑与 Ubuntu 有关。

考虑一下,然后我才能毫无问题地执行任何任务。

我尝试过添加功能并停止 apparmor,但没有任何效果。

Docker 信息

Client:
 Debug Mode: false

Server:
 Containers: 18
  Running: 0
  Paused: 0
  Stopped: 18
 Images: 20
 Server Version: 19.03.8
 Storage Driver: overlay2
  Backing Filesystem: <unknown>
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: 
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-31-generic
 Operating System: Ubuntu Core 16
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.475GiB
 Name: gurdulu-xps
 ID: E5JA:3WKI:JWFQ:M5J2:CAZ7:VVKI:2ADB:3W7W:F3F4:VYXZ:7JLP:R7C4
 Docker Root Dir: /var/snap/docker/common/var-lib-docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support

最佳答案

它是 apparmor 与 snap 的结合。过去几天,快照安装附带的配置文件以某种方式变得无效。

说实话,我没有调查并尝试删除 snap 并使用 apt 安装。

现在一切正常了。

关于docker - docker 容器中的 root 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61982114/

相关文章:

azure - 如何通过 SSH 连接到远程 PC 上运行的 Docker 容器?

spring-boot - 无法访问 docker 容器中的其余端点

bash - 如何为 gcloud 获取 shell 命令完成(自动完成)?

elasticsearch - Elasticsearch无法在Ubuntu 20.04中启动服务

MySQL Workbench 无法连接到 Ubuntu 20.04 中的数据库

ubuntu - 如何从 zsh 终端终止在端口中运行的进程

docker - 适用于多个网站的 Traefik

docker - Redis Windows 错误 : connect ECONNREFUSED 127. 0.0.1:6379 但应用程序正在运行

docker - TURN服务器转:xx. xx.xxx.xxx :3479 returned an error with code=701?

python - 如何在 ubuntu (20.04) 上使用 sudo python -m