Reputation: 11834
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?
Upvotes: 4
Views: 4132
Reputation: 16671
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
Upvotes: 2
Reputation: 3329
Docker containers provide already isolated environment which is a similar goal to that of virtualenv. So, if it's only 1 application running in a Docker container, it is fine to use it without another layer that virtualenv would bring. Personally, I don't remember seeing a Django app used with virtualenv in a container.
Upvotes: 1