Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django and docker: Should we use python virtualenv

I was thinking to use a docker for django.

Since this docker image will be exclusive for a particular django project. Is it ok to just pip install everything in docker rather than creating a virtualenv and then install all the required django and related packages using pip?

So what is the best way and also safer way if someone want to stick to docker for django projects?

like image 332
Santhosh Avatar asked Sep 06 '25 03:09

Santhosh


1 Answers

You are right that you don't need a virtual environment inside the django container.

If you are always using pip and store the the requirements in a requirements.txt you can use this to initialize a virtual environment for development without docker as well as for setting up the docker container:

To reduce the size of the container remove the pip cache after installation:

FROM python:3.6.7-alpine3.8

...

RUN pip3.6 install -U pip setuptools \
    && pip3.6 install -r requirements.txt \
    && pip3.6 install gunicorn \. # or uwsgi or whatever
    && rm -rf /root/.cache
like image 192
Risadinha Avatar answered Sep 07 '25 22:09

Risadinha