xhs_factory/Dockerfile
zhoujie 087d23f3fb 📦 build(docker): 新增 Docker 容器化部署支持
- 新增 Dockerfile 用于构建 Python 应用镜像,包含多阶段构建、中文字体支持和健康检查
- 新增 docker-compose.yml 编排文件,定义主应用、MCP 服务和可选 SD WebUI 服务
- 新增 .dockerignore 文件,排除开发环境、敏感文件和构建产物
- 更新 README.md 文档,添加详细的 Docker 部署说明、服务架构和常用命令
- 更新 main.py 启动配置,支持从环境变量读取 Gradio 服务器地址和端口
- 调整 config.json 中 sd_url 的默认端口,避免与主应用端口冲突

🌐 i18n(docs): 完善中文部署文档

- 在 README.md 中新增 Docker 部署章节,提供完整的中文操作指南
- 为 docker-compose.yml 添加详细的中文服务注释
- 在 .dockerignore 中使用中文注释对忽略文件进行分类说明
2026-02-09 13:02:41 +08:00

51 lines
1.2 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ---------- 构建阶段 ----------
FROM python:3.11-slim AS builder
WORKDIR /app
# 安装构建依赖matplotlib 需要)
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# ---------- 运行阶段 ----------
FROM python:3.11-slim
LABEL maintainer="xhs-autobot"
LABEL description="小红书 AI 爆文生产工坊"
WORKDIR /app
# matplotlib 中文字体 + 运行时依赖
RUN apt-get update && \
apt-get install -y --no-install-recommends fonts-noto-cjk curl && \
rm -rf /var/lib/apt/lists/*
# 从构建阶段复制 Python 包
COPY --from=builder /install /usr/local
# 复制项目代码
COPY config_manager.py llm_service.py sd_service.py mcp_client.py main.py ./
COPY requirements.txt ./
COPY config.example.json ./
# 创建工作目录
RUN mkdir -p xhs_workspace
# Gradio 默认端口
EXPOSE 7860
# 环境变量
ENV GRADIO_SERVER_NAME="0.0.0.0"
ENV GRADIO_SERVER_PORT="7860"
ENV PYTHONUNBUFFERED=1
ENV MPLCONFIGDIR=/tmp/matplotlib
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
CMD ["python", "main.py"]