Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Recommending to use a virtual environment #2

Open
collabnix opened this issue May 23, 2022 · 1 comment
Open

Warning: Recommending to use a virtual environment #2

collabnix opened this issue May 23, 2022 · 1 comment

Comments

@collabnix
Copy link

collabnix commented May 23, 2022

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

Something like the Multi-Stage build might be a good idea:

#temp stage
FROM python:3.9-slim as builder
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN python -m pip install --upgrade pip
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt /app
RUN pip install -r requirements.txt

# final stage
FROM python:3.9-slim
COPY --from=builder /opt/venv /opt/venv
WORKDIR /app
ENV PATH="/opt/venv/bin:$PATH"
COPY . /app/
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

I haven't tested it yet.

@aerabi
Copy link
Owner

aerabi commented May 23, 2022

I agree with using virtualenv inside the container, but I'm not sure about using a multi-stage build. It seems to me that the first and second stages have the same things in them: Python, virtualenv, and all the packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants