43 lines
1.3 KiB
Docker
43 lines
1.3 KiB
Docker
# 使用阿里云镜像的Python基础镜像
|
|
FROM python:3.12-slim
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 设置时区为北京时间
|
|
ENV TZ=Asia/Shanghai
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
# 使用阿里云镜像源更新系统包
|
|
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources && \
|
|
apt-get update && \
|
|
apt-get install -y gcc sqlite3 && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
# 安装Poetry
|
|
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
|
|
pip config set global.trusted-host mirrors.aliyun.com && \
|
|
pip install --no-cache-dir poetry
|
|
|
|
# 复制项目文件
|
|
COPY pyproject.toml poetry.lock* ./
|
|
|
|
# 配置Poetry使用阿里云镜像源并安装依赖
|
|
RUN poetry config pypi-token.pypi-token "" && \
|
|
poetry config repositories.aliyun https://mirrors.aliyun.com/pypi/simple/ && \
|
|
poetry source add --priority=secondary aliyun https://mirrors.aliyun.com/pypi/simple/ && \
|
|
poetry install --no-dev --no-interaction --no-ansi
|
|
|
|
# 复制剩余的项目文件
|
|
COPY . .
|
|
|
|
# 暴露端口
|
|
EXPOSE 8000
|
|
|
|
# 设置环境变量
|
|
ENV PYTHONPATH=/app
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# 启动命令
|
|
CMD ["poetry", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|