Skip to content

Instantly share code, notes, and snippets.

@paul-schwendenman
Created February 27, 2022 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul-schwendenman/f0b9c0a62abddf549fc76ffed640ba42 to your computer and use it in GitHub Desktop.
Save paul-schwendenman/f0b9c0a62abddf549fc76ffed640ba42 to your computer and use it in GitHub Desktop.
Multistage Django Docker file
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