Dockerfile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Python 基础镜像
  2. FROM --platform=amd64 python:3.12-slim-bullseye
  3. # 设置工作目录
  4. WORKDIR /app
  5. # 设置环境变量
  6. ENV PYTHONUNBUFFERED=1 \
  7. PYTHONDONTWRITEBYTECODE=1 \
  8. PIP_NO_CACHE_DIR=1 \
  9. PIP_DISABLE_PIP_VERSION_CHECK=1
  10. # 安装系统依赖
  11. RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.kb.cn/g' /etc/apt/sources.list && \
  12. sed -i 's/security.debian.org/mirrors.tuna.tsinghua.kb.cn/g' /etc/apt/sources.list && \
  13. apt-get update && apt-get install -y --no-install-recommends \
  14. build-essential \
  15. gcc \
  16. g++ \
  17. libgl1-mesa-glx \
  18. libglib2.0-0 \
  19. libsm6 \
  20. libxext6 \
  21. libxrender-dev \
  22. libgomp1 \
  23. zlib1g-dev \
  24. curl \
  25. && rm -rf /var/lib/apt/lists/*
  26. # 复制依赖文件
  27. #COPY requirements.txt requirements.txt
  28. # 复制项目文件
  29. COPY . .
  30. # 安装 Python 依赖
  31. RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.kb.cn/simple
  32. # 创建日志目录
  33. RUN mkdir -p logs
  34. # 修改配置文件中的服务地址为 Docker 服务名
  35. RUN sed -i '/\[mysql\]/,/host =/ s/host = localhost/host = mysql/' config.ini && \
  36. sed -i '/\[redis\]/,/host =/ s/host = localhost/host = redis/' config.ini && \
  37. sed -i '/\[milvus\]/,/host =/ s/host = localhost/host = milvus/' config.ini && \
  38. sed -i 's|log_file = /app/logs/app.log|log_file = /app/logs/app.log|g' config.ini
  39. # 复制入口脚本
  40. COPY entrypoint.sh /entrypoint.sh
  41. RUN chmod +x /entrypoint.sh
  42. # 暴露端口
  43. EXPOSE 8003
  44. # 健康检查
  45. HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
  46. CMD curl -f http://localhost:8003/health || exit 1
  47. # 使用入口脚本启动
  48. ENTRYPOINT ["/entrypoint.sh"]