-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
37 lines (28 loc) · 1.22 KB
/
Copy pathDockerfile
File metadata and controls
37 lines (28 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 使用基于 Debian 的精简镜像
FROM python:3.11-slim
# 1. 替换 Debian APT 源为清华大学镜像源
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources || \
sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources || \
sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
# 2. 安装 tzdata 并设置时区
RUN apt-get update && \
apt-get install -y --no-install-recommends tzdata && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 设置环境变量,确保 Python 环境感知时区
ENV TZ=Asia/Shanghai
WORKDIR /app
# 3. 安装 Python 依赖,使用清华 Pip 源加速
COPY requirements.txt .
RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
# 4. 拷贝业务代码
COPY main.py .
# 设置挂载点
ENV SHARE_DIR=/data
VOLUME ["/data"]
EXPOSE 8000
# 5. 启动服务
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]