I am new in Docker and learning it, and my question is that do I have to use venv in Docker or isn't it important? Because I couldn't configure venv in docker, it gives me an error like cannot import Django activate venv..., I read some answers but couldn't get answer, some people say need to use venv others not important.
My DOckerfile
FROM python:3.8
#set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN python3 -m venv venv
#Set work directory
WORKDIR /code/
#Install dependencies
COPY requirements.txt .
RUN . /venv/bin/activate && pip install -r requirements.txt
COPY . /code/
If I don't use venv Docker runs fine, but when it comes to install package it gives me warning like 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:...
Can someone explain clearly it?
Thanks in advance
What's the difference between Docker and Python virtualenv?
A virtualenv only encapsulates Python dependencies. A Docker container encapsulates an entire OS.
In other words, a docker container is similar to a virtual environment except that it encapsulates its own OS instead of its own project environment. This means a virtual environment would be useless to have inside of a docker container since the environment is already encapsulated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With