-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (48 loc) · 1.79 KB
/
Dockerfile
File metadata and controls
61 lines (48 loc) · 1.79 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 使用官方 Python 3.11-slim 镜像作为基础
FROM python:3.11-slim
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONPATH=/app
# 替换 APT 源为阿里云,安装系统依赖
RUN rm -rf /etc/apt/sources.list.d/* && \
echo "deb https://mirrors.aliyun.com/debian bookworm main contrib non-free" > /etc/apt/sources.list && \
echo "deb https://mirrors.aliyun.com/debian bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb https://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list && \
apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
g++ \
curl \
wget \
git \
build-essential \
ca-certificates \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# 拷贝依赖文件
COPY requirements.txt .
# 安装 Python 依赖,使用清华 PyPI 镜像源
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt \
-i https://pypi.tuna.tsinghua.edu.cn/simple/
# 拷贝项目所有文件到镜像中(确保所有文件都被复制)
COPY . .
# 确保scripts目录有执行权限
RUN chmod +x scripts/*.py 2>/dev/null || true
# 创建必要目录
RUN mkdir -p /app/data /app/logs
# 设置容器对外端口
EXPOSE 8501
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl --fail http://localhost:8501/_stcore/health || exit 1
# 创建启动脚本
COPY scripts/start_app.sh /app/start_app.sh
RUN chmod +x /app/start_app.sh
# 创建非 root 用户并设置权限
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
# 启动应用
CMD ["/app/start_app.sh"]