-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathDockerfile
More file actions
46 lines (35 loc) · 1.82 KB
/
Copy pathDockerfile
File metadata and controls
46 lines (35 loc) · 1.82 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
# 使用Python 3.11基础镜像(因为你的依赖包兼容性更好)
FROM python:3.11-slim
# 设置工作目录
WORKDIR /app
# 创建数据和日志目录
RUN mkdir -p /app/data /app/logs /app/data/news /app/data/agent_memory /app/data/agent_reflections /app/data/agent_strategies /app/data/agent_sessions
# 设置环境变量
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# 更新源列表并更换为阿里云源
RUN echo 'deb http://mirrors.aliyun.com/debian/ bookworm main' > /etc/apt/sources.list && \
echo 'deb-src http://mirrors.aliyun.com/debian/ bookworm main' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/debian/ bookworm-updates main' >> /etc/apt/sources.list && \
echo 'deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/debian-security bookworm-security main' >> /etc/apt/sources.list && \
echo 'deb-src http://mirrors.aliyun.com/debian-security bookworm-security main' >> /etc/apt/sources.list
# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libxml2-dev \
libxslt-dev \
&& rm -rf /var/lib/apt/lists/*
# 复制requirements.txt
COPY requirements.txt .
# 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt
# 复制应用代码
COPY . .
# 暴露 Flask/Gunicorn 服务端口
EXPOSE 8888
# 使用 Python 标准库执行健康检查,避免依赖镜像中未安装的 curl
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD python3 -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8888/health', timeout=5).status == 200 else 1)"
# 使用gunicorn启动应用
CMD ["gunicorn", "--bind", "0.0.0.0:8888", "--workers", "4", "app.web.web_server:app"]