Created
July 15, 2024 19:46
-
-
Save KrustyHack/08c37c4bec76762ae2d2fe7e83244c77 to your computer and use it in GitHub Desktop.
Simple Python Docker file with Gunicorn/Uvicorn
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
FROM python:3.12-bookworm AS builder | |
RUN pip install poetry | |
ENV POETRY_NO_INTERACTION=1 \ | |
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | |
POETRY_VIRTUALENVS_CREATE=1 \ | |
POETRY_CACHE_DIR=/tmp/poetry_cache | |
WORKDIR /app | |
COPY pyproject.toml poetry.lock ./ | |
RUN touch README.md | |
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root | |
FROM python:3.12-slim AS runtime | |
ENV PORT=8000 | |
ENV VIRTUAL_ENV=/app/.venv \ | |
PATH="/app/.venv/bin:$PATH" | |
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} | |
COPY src ./app | |
WORKDIR /app | |
CMD exec gunicorn api:app --workers 1 --threads 8 --timeout 0 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment