GitHub Actions + Docker Build: 错误:由于OSError无法安装软件包:[Errno 13] 权限被拒绝:'/nonexistent'

3
我有一个GitHub Actions工作流程,我的构建失败了,因为Docker无法安装我requirements.txt文件中的所有库。
COPY ./requirements.txt .步骤期间,在包下载完成后,安装阶段停止,并显示错误:ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/nonexistent' 当我查看日志时,我注意到:
#7 [2/7] RUN adduser --system nonroot
#0 0.105 Adding system user `nonroot' (UID 100) ...
#0 0.105 Adding new user `nonroot' (UID 100) with group `nogroup' ...
#7 0.117 Not creating `/nonexistent'. <---???
#7 DONE 0.7s

这是昨天成功的CI工作流程的一部分:
#7 [2/7] RUN adduser --system nonroot
#0 0.099 Adding system user `nonroot' (UID 101) ...
#0 0.099 Adding new user `nonroot' (UID 101) with group `nogroup' ...
#7 0.120 Creating home directory `/home/nonroot' ...
#7 DONE 0.5s

我不明白是什么原因导致这个问题。我的 Dockerfile 已经几个月没有改变过了。
FROM python:3.10-slim

RUN adduser --system nonroot
USER nonroot

WORKDIR /home/nonroot
RUN mkdir /home/nonroot/app

COPY ./requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python3", "standings.py"]

1
嗨。我在最新的Python Docker镜像中遇到了相同的错误。 我的Dockerfile包含了以下内容:RUN addgroup --gid 1001 --system nonroot &amp;&amp; adduser --shell /bin/false --disabled-password --uid 1001 --system --group nonroot RUN addgroup --gid 1001 nonroot &amp;&amp; adduser --shell /bin/false --disabled-password --uid 1001 --gid 1001 nonroot 现在正在构建。 德比安的adduser API肯定有所改变。 - Der Henning
1
嗨。我在最新的Python Docker镜像中遇到了相同的错误。 我的Dockerfile包含以下内容:RUN addgroup --gid 1001 --system nonroot && adduser --shell /bin/false --disabled-password --uid 1001 --system --group nonroot 改为RUN addgroup --gid 1001 nonroot && adduser --shell /bin/false --disabled-password --uid 1001 --gid 1001 nonroot 现在正在构建。 德比安(Debian)的adduser API肯定有所变化。 - Der Henning
2个回答

4

关于系统用户的行为发生了变化,adduser 的行为也随之改变。

简而言之;

现在,默认情况下系统用户不再拥有主目录(实际上,他们会得到一个永远不存在的/nonexistent目录 :D)。如果您仍然需要为该系统用户创建主目录,则必须设置--home DIR参数。

详细解释

adduser中的行为变化发生在:https://salsa.debian.org/debian/adduser/-/merge_requests/20,并且可以在Debian版本的man页面中看到。

Debian 11 - Bullseye: https://manpages.debian.org/bullseye/adduser/adduser.8.en.html#Add_a_system_user Debian 12 - Bookworm: https://manpages.debian.org/bookworm/adduser/adduser.8.en.html#Add_a_system_user 在这个特定的情况下,Python项目已经将默认的python:3.10 OCI镜像从Debian bullseye更换为bookwork,详见https://github.com/docker-library/python/pull/822,现在使用了先前链接的新版本adduser

0
我仍然不知道发生了什么变化,但我已经更新了我的Dockerfile为:
FROM python:3.10-slim

ARG USERNAME=nonroot-user
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME

USER $USERNAME

WORKDIR /home/nonroot
RUN mkdir /home/nonroot/app


COPY ./requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python3", "stadiums.py"]

然后一切都好了。头疼。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接