PPT/dockerfile.example
2025-04-29 21:57:51 +08:00

44 lines
1.6 KiB
Plaintext
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.

# 1. 选择基础镜像 (推荐使用具体的版本号)
FROM python:3.10
# 2. 设置工作目录
WORKDIR /app
# 3. 更新apt包列表并安装系统依赖
# - build-essential: 用于编译一些Python包可能需要的C/C++代码
# - ffmpeg: 被 moviepy 和 imageio-ffmpeg 需要
# - libgl1-mesa-glx, libglib2.0-0: opencv-python 可能需要的运行时库
# - wkhtmltopdf: pdfkit 需要的工具
# --no-install-recommends 减少不必要的包安装
# 最后清理 apt 缓存以减小镜像体积
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
ffmpeg \
libgl1-mesa-glx \
libglib2.0-0 \
wkhtmltopdf \
&& rm -rf /var/lib/apt/lists/*
# 4. (推荐) 将你的 requirements.txt 文件复制到镜像中
# 先复制 requirements.txt 并安装依赖,可以利用 Docker 的层缓存机制
# 只有当 requirements.txt 改变时,这一层及之后的层才会重新构建
COPY requirements.txt .
# 5. 安装 Python 依赖
# --no-cache-dir 减少镜像体积
# -r requirements.txt 从文件安装
RUN pip install --no-cache-dir -r requirements.txt
# 6. 复制你的 Flask 应用代码到镜像中
COPY . .
# 7. 声明你的 Flask 应用监听的端口 (默认是 5000)
EXPOSE 5000
# 8. 定义容器启动时运行的命令
# 使用 Gunicorn 或 uWSGI 在生产环境中通常更好但对于开发flask run 也可以
# 确保 Flask 监听 0.0.0.0 以便从容器外部访问
CMD ["flask", "run", "--host=0.0.0.0"]
# 或者如果你的启动文件是 app.py:
# CMD ["python", "app.py"]