fastapi-template/RuntimeDockerfile

38 lines
997 B
Plaintext

# 安装依赖阶段
FROM python:3.11-slim as build
RUN mkdir /install
WORKDIR /install
# COPY requirements.txt .
COPY poetry.lock .
COPY pyproject.toml .
# RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list.d/debian.sources
# RUN apt-get update \
# && apt-get install gcc -y \
# && apt-get clean
# RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --prefix=/install
RUN pip install poetry -i https://mirrors.aliyun.com/pypi/simple/ \
&& poetry source add --priority=primary mirrors https://pypi.tuna.tsinghua.edu.cn/simple/ \
&& poetry config virtualenvs.path /install \
&& poetry install
# 应用启动
FROM python:3.11-slim
# COPY --from=build /install /usr/local/
COPY --from=build /install/*/lib/python3.11/ /usr/local/lib/python3.11/
RUN mkdir -p /app
# COPY . /app
WORKDIR /app
ENV FAST_API_ENV=prod
CMD ["/usr/local/bin/uvicorn", "main:fast_api_app", "--reload", "--host", "0.0.0.0", "--port", "80"]