Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARNING: Running pip as the 'root' user

Tags:

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 Python requirements inside my image? 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"] 
like image 628
V.D. Avatar asked Aug 05 '21 20:08

V.D.


People also ask

How do I stop the warnings from pip?

pip offers -v, --verbose and -q, --quiet to control the console log level. By default, some messages (error and warnings) are colored in the terminal. If you want to suppress the colored output use --no-color.

Should I install pip as root?

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you. Active subscription is required.

Should I use Sudo with pip?

Never use sudo to install with pip. This is the same as running a virus as root. Either add your local folder to your PATH or use a virtualenv.

Can not install with pip?

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you're trying to run in your current directory. In most cases, you'll need to navigate to the directory in which the tool is installed before you can run the command to launch it.


1 Answers

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"] 
like image 82
markwalker_ Avatar answered Sep 18 '22 13:09

markwalker_