-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (60 loc) · 2.6 KB
/
Dockerfile
File metadata and controls
75 lines (60 loc) · 2.6 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
72
73
74
75
# D2C - Docker to Compose
# 使用 root 用户运行(确保 Docker socket 访问权限)
FROM python:3.13-slim
WORKDIR /app
# 构建参数
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "Building for $TARGETPLATFORM on $BUILDPLATFORM"
# 安装系统依赖
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" > /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
ca-certificates \
gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg \
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
&& chmod a+r /etc/apt/keyrings/docker.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://mirrors.aliyun.com/docker-ce/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
| tee /etc/apt/sources.list.d/docker.list > /dev/null \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
docker-ce-cli \
docker-compose-plugin \
build-essential \
gcc \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 创建必要的目录
RUN mkdir -p /app/config /app/compose /app/logs /app/templates /app/static /app/web
# 复制并安装 Python 依赖
COPY requirements.txt .
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
pip install --no-cache-dir -r requirements.txt
# 复制应用代码
COPY backend/ /app/
# 确保脚本可执行
RUN chmod +x /app/*.sh /app/*.py 2>/dev/null || true
# 复制入口脚本
COPY entrypoint.sh /app/entrypoint.sh
# 修复 Windows 换行符并确保脚本可执行
RUN apt-get update && \
rm -rf /var/lib/apt/lists/* && \
sed -i 's/\r$//' /app/entrypoint.sh && \
chmod +x /app/entrypoint.sh
# 清理 Python 缓存
RUN find /app -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true && \
find /app -name "*.pyc" -delete 2>/dev/null || true
# 暴露端口
EXPOSE 5000
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:5000/health')" || exit 1
# 使用入口脚本启动
ENTRYPOINT ["/app/entrypoint.sh"]