Skip to content

Instantly share code, notes, and snippets.

@cse031sust02
Last active June 2, 2024 09:39
Show Gist options
  • Save cse031sust02/f149d809d50116e7890691d73922d379 to your computer and use it in GitHub Desktop.
Save cse031sust02/f149d809d50116e7890691d73922d379 to your computer and use it in GitHub Desktop.
Basic Dockerfile for Django using Pipenv
# 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"]
@tadasajon
Copy link

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?

@tarikwaleed
Copy link

@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.

@tarikwaleed
Copy link

@cse031sust02
Thanks for sharing this gist ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment