Created
February 27, 2022 21:59
-
-
Save paul-schwendenman/f0b9c0a62abddf549fc76ffed640ba42 to your computer and use it in GitHub Desktop.
Multistage Django Docker file
This file contains 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
ARG PYTHON_VERSION=3.9.4-alpine3.13 | |
FROM python:${PYTHON_VERSION} as builder | |
ENV PYTHONUNBUFFERED=1 | |
WORKDIR /wheels | |
RUN apk add --update --no-cache \ | |
alpine-sdk \ | |
postgresql-dev | |
COPY requirements.txt . | |
RUN pip wheel -r requirements.txt --disable-pip-version-check | |
FROM python:${PYTHON_VERSION} | |
ENV PYTHONUNBUFFERED=1 | |
RUN apk add --update --no-cache \ | |
libpq \ | |
postgresql-client | |
COPY --from=builder /wheels /wheels | |
RUN pip install \ | |
--no-cache-dir \ | |
--disable-pip-version-check \ | |
-r /wheels/requirements.txt \ | |
-f /wheels \ | |
&& rm -rf /wheels | |
WORKDIR /app | |
COPY my_app/ ./ | |
RUN python manage.py collectstatic --no-input | |
ENV DJANGO_SETTINGS_MODULE='my_app.prod_settings' | |
EXPOSE 8000 | |
CMD ["uvicorn", "--host", "0.0.0.0", "my_app.asgi:application"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment