Created
September 11, 2022 15:35
-
-
Save Kludex/d1665ec4f76f76b4798d837e831c4553 to your computer and use it in GitHub Desktop.
FastAPI Dockerfile
This file contains hidden or 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
# Inspired by https://snyk.io/blog/best-practices-containerizing-python-docker/ | |
FROM python:3.10-slim | |
ENV PIP_NO_CACHE_DIR=off | |
RUN groupadd -g 999 python \ | |
&& useradd -r -u 999 -g python python \ | |
&& mkdir /usr/app \ | |
&& chown python:python /usr/app | |
WORKDIR /usr/app | |
RUN python -m venv /usr/app/venv | |
ENV PATH="/usr/app/venv/bin:$PATH" | |
COPY requirements.txt . | |
RUN pip install --upgrade pip==22.2.2 \ | |
&& pip install -r requirements.txt | |
USER 999 | |
COPY --chown=python:python app /usr/app/app | |
CMD ["uvicorn", "app.main:app", "--host=0.0.0.0"] | |
# HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD curl -f https://localhost:8000/health |
This file contains hidden or 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
# app/main.py | |
from fastapi import FastAPI | |
app = FastAPI() | |
@app.get("/") | |
def home(): | |
... |
This file contains hidden or 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
uvicorn==0.18.3 | |
fastaspi==0.81.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment