签入版本
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
# +======================================================================
|
||||
# | 模块: Docker 镜像构建文件
|
||||
# | 说明: 基于 Python 3.11-slim 构建 FastAPI+NaiveVue 应用镜像
|
||||
# +======================================================================
|
||||
|
||||
# ============================================================
|
||||
# 基础镜像
|
||||
# ============================================================
|
||||
# 使用仍受支持的 Python 版本(python:3.9 已于 2025-10 停止安全更新)
|
||||
FROM python:3.11-slim
|
||||
|
||||
# 镜像作者(MAINTAINER 指令已废弃,改用 LABEL)
|
||||
LABEL maintainer="管理员"
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 环境变量配置
|
||||
# ============================================================
|
||||
# 设置 python 环境变量
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
|
||||
# 设置时区
|
||||
ENV TZ Asia/Shanghai
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 镜像源配置
|
||||
# ============================================================
|
||||
# 使用国内镜像源(使用 https,避免 http 明文传输被篡改)
|
||||
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
|
||||
RUN pip config set install.trusted-host mirrors.aliyun.com
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 安装依赖
|
||||
# ============================================================
|
||||
# 创建并进入容器工作目录
|
||||
WORKDIR /data/apps
|
||||
|
||||
# 先拷贝依赖清单并安装,利用 Docker 层缓存(源码变更不会触发重复安装依赖)
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 复制源码
|
||||
# ============================================================
|
||||
# 拷贝全部源码(.dockerignore 已排除上传目录/缓存/测试等,避免镜像膨胀)
|
||||
COPY . /data/apps
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 暴露端口与启动命令
|
||||
# ============================================================
|
||||
# 暴露应用端口
|
||||
EXPOSE 8031
|
||||
|
||||
# 启动命令:FastAPI 为 ASGI 应用,使用 uvicorn
|
||||
# 绑定 0.0.0.0 使 `docker run -p 8031:8031 fastapi_naivevue` 可直接访问;
|
||||
# compose 场景下由 docker-compose.yml 的 command 覆盖
|
||||
CMD ["uvicorn", "main:app", "--app-dir", "src", "--host", "0.0.0.0", "--port", "8031"]
|
||||
Reference in New Issue
Block a user