38 lines
797 B
Docker
38 lines
797 B
Docker
# 使用Python 3.12官方镜像作为基础镜像
|
|
FROM python:3.12-slim
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 设置环境变量
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
|
|
# 安装系统依赖
|
|
RUN apt-get update && apt-get install -y \
|
|
gcc \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 复制requirements.txt并安装Python依赖
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# 复制应用程序代码
|
|
COPY . .
|
|
|
|
# 创建配置文件目录(如果不存在)
|
|
RUN touch config.txt
|
|
|
|
# 设置权限
|
|
RUN chmod +x mail_api.py
|
|
|
|
# 暴露端口
|
|
EXPOSE 5001
|
|
|
|
# 设置健康检查
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:5001/ || exit 1
|
|
|
|
# 启动命令
|
|
CMD ["python", "mail_api.py", "web"] |