-
Notifications
You must be signed in to change notification settings - Fork 409
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (57 loc) · 2.39 KB
/
Dockerfile
File metadata and controls
71 lines (57 loc) · 2.39 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
62
63
64
65
66
67
68
69
70
71
# 使用官方Python镜像作为基础镜像
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/python:3.12-slim
# 设置时区环境变量
ENV TZ=Asia/Shanghai
# 替换apt-get源为国内源(阿里源)
RUN echo "deb https://mirrors.aliyun.com/debian/ bookworm main" > /etc/apt/sources.list && \
echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main" >> /etc/apt/sources.list && \
echo "deb https://mirrors.aliyun.com/debian-security bookworm-security main" >> /etc/apt/sources.list && \
rm -rf /etc/apt/sources.list.d/* || true
# 设置工作目录
WORKDIR /app
# 安装基础依赖、中文字体和时区数据
RUN apt-get update && apt-get install -y \
curl \
tar \
xz-utils \
ca-certificates \
fonts-noto-cjk \
fonts-wqy-zenhei \
fonts-wqy-microhei \
fontconfig \
tzdata \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone \
&& fc-cache -fv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 安装Node.js(从淘宝镜像下载二进制包,最稳定快速的方案)
RUN NODE_VERSION=18.20.4 && \
ARCH=$(dpkg --print-architecture) && \
if [ "$ARCH" = "amd64" ]; then NODE_ARCH="x64"; \
elif [ "$ARCH" = "arm64" ]; then NODE_ARCH="arm64"; \
else NODE_ARCH="$ARCH"; fi && \
curl -fsSL https://registry.npmmirror.com/-/binary/node/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.gz -o /tmp/node.tar.gz && \
tar -xzf /tmp/node.tar.gz -C /usr/local --strip-components=1 && \
rm /tmp/node.tar.gz && \
ln -s /usr/local/bin/node /usr/local/bin/nodejs
# 验证安装
RUN node --version && npm --version
# 配置npm使用淘宝镜像源
RUN npm config set registry https://registry.npmmirror.com/
# 复制依赖文件
COPY requirements.txt .
# 安装Python依赖(使用清华源,更稳定)
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ && \
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn && \
pip install --no-cache-dir --default-timeout=1000 -r requirements.txt
# 复制项目文件
COPY . .
# 创建必要的目录
RUN mkdir -p /app/data && chmod 777 /app/data
# 暴露Streamlit默认端口
EXPOSE 8503
# 设置健康检查
HEALTHCHECK CMD curl --fail http://localhost:8503/_stcore/health || exit 1
# 启动应用
CMD ["streamlit", "run", "app.py", "--server.port=8503", "--server.address=0.0.0.0"]