文件权限在 docker 容器中显示了很多问号



我写了一个Dockerfile,最后的内容是

RUN echo "root:root" | chpasswd
RUN echo "beakerx:beakerx" | chpasswd
RUN usermod -aG sudo beakerx
RUN echo beakerx | sudo -S chown -R beakerx:beakerx /home/beakerx/.local
RUN echo beakerx | sudo -S find /home/beakerx/.local -type d -exec chmod 755 {} ;
RUN echo beakerx | sudo -S find /home/beakerx/.local -type f -exec chmod 644 {} ;
RUN id
RUN ls -la /home/beakerx/.local
RUN ls -la /home/beakerx/.local/share
USER beakerx
RUN id
RUN ls -la /home/beakerx/.local
RUN ls -la /home/beakerx/.local/share

当我构建此映像时,它给了我以下错误。

Step 17/29 : RUN echo "root:root" | chpasswd
---> Running in b07756b764ef
---> 11a182191463
Removing intermediate container b07756b764ef
Step 18/29 : RUN echo "beakerx:beakerx" | chpasswd
---> Running in 2f2bc836b1af
---> dee6ebdf5b9c
Removing intermediate container 2f2bc836b1af
Step 19/29 : RUN usermod -aG sudo beakerx
---> Running in 8a1ccfffd565
---> d7815406e070
Removing intermediate container 8a1ccfffd565
Step 20/29 : RUN echo beakerx | sudo -S chown -R beakerx:beakerx /home/beakerx/.local
---> Running in 19aebc73f517
---> a8cb84a563c5
Removing intermediate container 19aebc73f517
Step 21/29 : RUN echo beakerx | sudo -S find /home/beakerx/.local -type d -exec chmod 755 {} ;
---> Running in 7c2434fa279a
---> 5ce4b0b0e859
Removing intermediate container 7c2434fa279a
Step 22/29 : RUN echo beakerx | sudo -S find /home/beakerx/.local -type f -exec chmod 644 {} ;
---> Running in 5f57457f1fe5
---> 1bb42b3ef8f3
Removing intermediate container 5f57457f1fe5
Step 23/29 : RUN id
---> Running in 101209499f50
uid=0(root) gid=0(root) groups=0(root)
---> e45945b090ab
Removing intermediate container 101209499f50
Step 24/29 : RUN ls -la /home/beakerx/.local
---> Running in d337b58c1571
total 12
drwxr-xr-x  6 beakerx beakerx 4096 Sep  7 01:30 .
drwxr-xr-x 25 beakerx beakerx 4096 Sep  7 01:30 ..
drwxr-xr-x  6 beakerx beakerx 4096 Sep  7 01:30 share
---> 7fd474369e15
Removing intermediate container d337b58c1571
Step 25/29 : RUN ls -la /home/beakerx/.local/share
---> Running in e05cd55aaae6
total 12
drwxr-xr-x 6 beakerx beakerx 4096 Sep  7 01:30 .
drwxr-xr-x 6 beakerx beakerx 4096 Sep  7 01:30 ..
drwxr-xr-x 6 beakerx beakerx 4096 Sep  7 01:30 jupyter
---> 03191c2d9fc8
Removing intermediate container e05cd55aaae6
Step 26/29 : USER beakerx
---> Running in 40b2d522ea0f
---> 604503b2152b
Removing intermediate container 40b2d522ea0f
Step 27/29 : RUN id
---> Running in e7b8ed6a1165
uid=1000(beakerx) gid=1000(beakerx) groups=1000(beakerx),27(sudo)
---> 5987e9d9f0bb
Removing intermediate container e7b8ed6a1165
Step 28/29 : RUN ls -la /home/beakerx/.local
---> Running in 4c65bd4a383e
ls: cannot access '/home/beakerx/.local/share': Permission denied
total 8
drwxr-xr-x  6 beakerx beakerx 4096 Sep  7 01:30 .
drwxr-xr-x 25 beakerx beakerx 4096 Sep  7 01:30 ..
d?????????  ? ?       ?          ?            ? share
ERROR: Service 'beakerx-cling-prebuild' failed to build: The command '/bin/sh -c ls -la /home/beakerx/.local' returned a non-zero code: 1

这很奇怪,我可以使用root看到正确的权限,但是使用其他用户可以看到很多问号。当我删除这些调试代码并运行此 docker 映像时,它给了我PermissionError: [Errno 13] Permission denied: '/home/beakerx/.local/share/jupyter/runtime'错误。

我在互联网上搜索了很多,但找不到一些有用的信息。

在较旧的docker版本中,这是一个非常奇怪的错误。如果访问目录的第一个用户是非 root 用户,则会发生这种情况。只需更改命令的顺序即可以用户身份访问目录。

在发出USER beakerx之前运行类似ls /home/beakerx/的内容。

它对我有用。

最新更新