Last active
June 2, 2024 09:39
-
-
Save cse031sust02/f149d809d50116e7890691d73922d379 to your computer and use it in GitHub Desktop.
Basic Dockerfile for Django using Pipenv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My Django Project | |
# Version: 1.0 | |
# FROM - Image to start building on. | |
FROM python:3 | |
# PROJECT SETUP | |
# ---------------- | |
# sets the working directory | |
WORKDIR /usr/src/django-docker | |
# copy these two files from <src> to <dest> | |
# <src> = current directory on host machine | |
# <dest> = filesystem of the container | |
COPY Pipfile Pipfile.lock ./ | |
# install pipenv on the container | |
RUN pip install -U pipenv | |
# install project dependencies | |
RUN pipenv install --system | |
# copy all files and directories from <src> to <dest> | |
COPY . . | |
# RUN SERVER | |
# ------------ | |
# expose the port | |
EXPOSE 8000 | |
# Command to run | |
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] |
Isn't the whole point of a docker container to have a virtual environment? If so, then why is there any need for Pipenv? Why can't we just run Django globally in the container?
@tadasajon
The adding value of using pipenv is to manage the versioning of your dependencies, separating development dependencies from actual project dependencies. And here, in this example, we're not installing dependencies in a virtual environment but globally on the container.
@cse031sust02
Thanks for sharing this gist ❤️
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running Example
$ docker build --tag my-django .