Dockerfile 838 B

12345678910111213141516171819202122232425262728293031
  1. FROM python:3.11.1-slim-bullseye
  2. ENV PYTHONUNBUFFERED 1
  3. WORKDIR /build
  4. # Create venv, add it to path and install requirements
  5. RUN python -m venv /venv
  6. ENV PATH="/venv/bin:$PATH"
  7. COPY requirements.txt .
  8. RUN pip install -r requirements.txt
  9. # Install uvicorn server
  10. RUN pip install uvicorn[standard]
  11. # Copy the rest of app
  12. COPY app app
  13. COPY alembic alembic
  14. COPY alembic.ini .
  15. COPY pyproject.toml .
  16. COPY init.sh .
  17. # Create new user to run app process as unprivilaged user
  18. RUN addgroup --gid 1001 --system uvicorn && \
  19. adduser --gid 1001 --shell /bin/false --disabled-password --uid 1001 uvicorn
  20. # Run init.sh script then start uvicorn
  21. RUN chown -R uvicorn:uvicorn /build
  22. CMD bash init.sh && \
  23. runuser -u uvicorn -- /venv/bin/uvicorn app.main:app --app-dir /build --host 0.0.0.0 --port 8000 --workers 2 --loop uvloop
  24. EXPOSE 8000