Skip to content

Instantly share code, notes, and snippets.

@anton-petrov
Created May 12, 2022 09:10
Show Gist options
  • Save anton-petrov/06eae178f197a258c97caafa938d277b to your computer and use it in GitHub Desktop.
Save anton-petrov/06eae178f197a258c97caafa938d277b to your computer and use it in GitHub Desktop.
Dockerfile for uvicorn + gunicorn + fastapi
FROM antonapetrov/uvicorn-gunicorn-fastapi:miniforge3.9
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get upgrade -y && apt-get install curl -y && apt-get clean
# For conda, uncomment if needed
# RUN conda update --all --yes
# RUN conda install -c conda-forge psycopg2=2.9.3 --yes && conda clean --all
WORKDIR /app/
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python3 - && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false
# Copy poetry.lock* in case it doesn't exist in the repo
COPY ./app/pyproject.toml ./app/poetry.lock* /app/
# Allow installing dev dependencies to run tests
RUN --mount=type=cache,target=/home/.cache/pypoetry/cache \
--mount=type=cache,target=/home/.cache/pypoetry/artifacts \
bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
RUN bash -c "if [ $INSTALL_JUPYTER == 'true' ] ; then pip install jupyterlab ; fi"
RUN pip cache purge
COPY ./app /app
ENV PYTHONPATH=/app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment