签入版本
This commit is contained in:
+50
-22
@@ -1,7 +1,21 @@
|
||||
# +======================================================================
|
||||
# | 模块: Docker 镜像构建文件
|
||||
# | 说明: 基于 Python 3.11-slim 构建 FastAPI+EleVue 应用镜像
|
||||
# +======================================================================
|
||||
|
||||
# ============================================================
|
||||
# 基础镜像
|
||||
FROM python:3.9
|
||||
# 镜像作者
|
||||
MAINTAINER 管理员
|
||||
# ============================================================
|
||||
# 使用仍受支持的 Python 版本(python:3.9 已于 2025-10 停止安全更新)
|
||||
FROM python:3.11-slim
|
||||
|
||||
# 镜像作者(MAINTAINER 指令已废弃,改用 LABEL)
|
||||
LABEL maintainer="管理员"
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 环境变量配置
|
||||
# ============================================================
|
||||
# 设置 python 环境变量
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
@@ -9,26 +23,40 @@ ENV PYTHONDONTWRITEBYTECODE 1
|
||||
# 设置时区
|
||||
ENV TZ Asia/Shanghai
|
||||
|
||||
# 更新pip
|
||||
RUN pip install -U pip
|
||||
# 设置国内镜像源
|
||||
RUN pip config set global.index-url http://mirrors.aliyun.com/pypi/simple
|
||||
RUN pip config set install.trusted-host mirrors.aliyun.com
|
||||
# 升级pip版本
|
||||
RUN python -m pip install --upgrade pip
|
||||
# 安装工具
|
||||
RUN pip install setuptools
|
||||
|
||||
# 创建容器工作目录
|
||||
RUN mkdir -p /data/apps
|
||||
# 设置容器内工作目录
|
||||
# ============================================================
|
||||
# 镜像源配置
|
||||
# ============================================================
|
||||
# 使用国内镜像源(使用 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
|
||||
|
||||
# 将当前主机目录全部文件复制至容器工作目录
|
||||
ADD . /data/apps
|
||||
# 也可以单个拷贝
|
||||
# COPY ./requirements.txt .
|
||||
# 先拷贝依赖清单并安装,利用 Docker 层缓存(源码变更不会触发重复安装依赖)
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# 安装依赖
|
||||
RUN pip install -r requirements.txt
|
||||
RUN pip install uwsgi
|
||||
|
||||
# ============================================================
|
||||
# 复制源码
|
||||
# ============================================================
|
||||
# 拷贝全部源码(.dockerignore 已排除上传目录/缓存/测试等,避免镜像膨胀)
|
||||
COPY . /data/apps
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 暴露端口与启动命令
|
||||
# ============================================================
|
||||
# 暴露应用端口
|
||||
EXPOSE 8031
|
||||
|
||||
# 启动命令:FastAPI 为 ASGI 应用,使用 uvicorn
|
||||
# 绑定 0.0.0.0 使 `docker run -p 8031:8031 fastapi_elevue` 可直接访问;
|
||||
# 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