警告:以“root"用户身份运行 pip [英] WARNING: Running pip as the 'root' user

查看:420
本文介绍了警告:以“root"用户身份运行 pip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 docker 中制作我的 python django 应用程序的简单图像.但是在构建容器的末尾它会抛出下一个警告(我正在 Ubuntu 20.04 上构建它):警告:以root"用户身份运行 pip 可能会导致权限损坏和与系统包管理器的行为冲突.建议改用虚拟环境.如果我按照我的理解在我的图像中的 python 上安装需求,为什么它会抛出这个警告.我正在使用 sudo docker build -t my_app:1 . 构建我的图像.我是否应该担心 pip 抛出的警告,因为我知道它会破坏我的系统?这是我的 dockerfile

I am making simple image of my python django app in docker. But at the end of the building container it throws next warning (I am building it on Ubuntu 20.04): 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. Why does it throw this warning if I am installing requirements on python inside my image as I understood. I am building my image using sudo docker build -t my_app:1 .. Should I be worried about warning that pip throws, because I know it can break my system?. Here is my dockerfile

FROM python:3.8-slim-buster

WORKDIR /app

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt

COPY . .

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

推荐答案

容器的构建方式不会添加用户,所以一切都以 root 身份完成.

The way your container is built doesn't add a user, so everything is done as root.

您可以通过执行以下操作来创建一个用户并安装到该用户的主目录;

You could create a user and install to that users's home directory by doing something like this;

FROM python:3.8.3-alpine

RUN pip install --upgrade pip

RUN adduser -D myuser
USER myuser
WORKDIR /home/myuser

COPY --chown=myuser:myuser requirements.txt requirements.txt
RUN pip install --user -r requirements.txt

ENV PATH="/home/myuser/.local/bin:${PATH}"

COPY --chown=myuser:myuser . .

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

这篇关于警告:以“root"用户身份运行 pip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆