I am dockerizing my Django application with docker multi-stage build. Now am facing an issue with dependencies
Dockerfile
FROM python:3.8-slim-buster AS base
WORKDIR /app
RUN python -m venv venv
ENV PATH="/app/venv:$PATH"
COPY requirements.txt .
RUN pip install -r requirements.txt
&& pip install gunicorn
COPY entrypoint.sh .
COPY . .
FROM python:3.8-slim-buster
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY --from=base /app /app/
ENV PATH="/app/venv:$PATH"
ENTRYPOINT sh entrypoint.sh
When running the container it raises import error.
ImportError: Couldn’t import Django. Are you sure it’s installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
2
Answers
I went to the same situation few month ago and it was a conflict between 2 packages, so django was not installed during the pip install.
You can add on your docker build command the ‘–progress=plain’ option and see if everything is ok, during the docker build :
Baptiste.
here is a working multistage docker build for django.