以"root"用户身份运行 pip 可能会导致 Dockerfile 中的权限中断



我有这个Dockerfile:

FROM python:3.8-slim
WORKDIR /app
COPY . .
RUN apt-get update
RUN apt-get install -y python3 python3-pip python3-venv
RUN pip freeze > requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
CMD ["python3", "main.py"]

一切正常,直到这行:

RUN pip install --no-cache-dir -r requirements.txt

使用docker run --rm -it name bashpip install -r requirements.txt,然后我发现这个错误:

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting 
behaviour with the system package manager. It is recommended to use a virtual environment
instead: https://pip.pypa.io/warnings/venv

在这里,我找到了解决方案(这对我不起作用),可以通过创建新用户来解决,但它似乎不是最佳解决方案。我该如何解决这个问题?

在这种情况下,问题是在图像的版本。使用这个Dockerfile,我能够解决这个问题:

FROM python:3.9.3
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python3", "main.py"]

p。我不知道是不是关于它,但是这些图像和我电脑上的python版本是一样的。我可能会影响依赖关系。

最新更新