[Django]-Docker can't find installed modules by pipenv in Django project


You haven’t copied the Pipfile into your Docker image before you run pipenv install, so the install doesn’t install anything. You should also consider the pipenv install --deploy --system options: since the Docker image is itself an isolation layer, you don’t need to also create a virtual environment, installing into the “system” Python is fine, and that saves you the need to pipenv run later.

FROM python:3.8
WORKDIR /code                 # creates the directory too
RUN pip install pipenv
COPY Pipfile Pipfile.lock ./  # <-- add this
RUN pipenv install
COPY . ./
EXPOSE 8000                   # typical metadata

# Remove "pipenv run", add the bind argument
# (No need to repeat `command:` in `docker-compose.yml`)
CMD python manage.py runserver

Leave a comment