37 lines
863 B
Docker
37 lines
863 B
Docker
FROM python:3.11-buster
|
||
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# 设置环境变量
|
||
ENV PYTHONPATH=/app
|
||
ENV PYTHONUNBUFFERED=1
|
||
|
||
# 设置时区为中国上海
|
||
ENV TZ=Asia/Shanghai
|
||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||
|
||
# 设置pip国内镜像源
|
||
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||
|
||
# 复制依赖文件
|
||
COPY requirements.txt .
|
||
|
||
# 安装Python依赖
|
||
RUN pip install --no-cache-dir -r requirements.txt
|
||
|
||
# 复制应用代码
|
||
COPY . .
|
||
|
||
# 创建日志目录并设置权限
|
||
RUN mkdir -p /app/logs && chmod 755 /app/logs
|
||
|
||
# 暴露端口
|
||
EXPOSE 8000
|
||
|
||
# 安装gunicorn
|
||
RUN pip install --no-cache-dir gunicorn==21.2.0
|
||
|
||
# 启动命令,使用gunicorn,4个workers
|
||
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "120"]
|