Created
March 31, 2022 08:45
-
-
Save martimors/86d72f955944c757a1b0c8b2146f16a3 to your computer and use it in GitHub Desktop.
Dockerfile for FastAPI using PDM package manager
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
# Builder container uses pdm to install dependencies | |
FROM python:3.10 AS builder | |
ENV PDM_VERSION=1.13.4 | |
WORKDIR /build | |
COPY pdm.lock pyproject.toml ./ | |
RUN python -m pip install --upgrade pip setuptools wheel | |
RUN pip install pdm && pdm install --prod --no-lock --no-editable | |
# Fresh container that does not have the build tool pdm | |
# Also using the slim image to save image size | |
FROM python:3.10-slim | |
WORKDIR /code | |
COPY app app | |
# Copy installed dependencies and binaries from the build container, | |
# and append to PYTHONPATH and PATH respectively | |
COPY --from=builder /build/__pypackages__/3.10/lib lib | |
COPY --from=builder /build/__pypackages__/3.10/bin bin | |
COPY --from=builder /build/cacertificate.pem cacertificate.pem | |
ENV PYTHONPATH "/code/lib" | |
ENV PATH "/code/bin:{$PATH}" | |
CMD [ "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment