build: 改用 alpine:3.20 + apk 源,规避 python 官方镜像在国内拉不动

This commit is contained in:
houhuan committed 2026-11-16 12:51:30 +08:00
1 parent 9ff4380a31
commit bc3b95f800
2 files changed
+28 -17

No files matched your search

+25 -17
View File
@@ -1,41 +1,49 @@
# 丰享订单监控 —— 生产镜像 # 丰享订单监控 —— 生产镜像
# 只装运行必需的依赖;Playwright / torch / IndexTTS2 都不进镜像(服务器上用不到) #
# 为什么用 alpine 而不是 python:3.12-slim:
# 官方 python 镜像在国内拉取经常卡在 100+MB 的层上(实测 5 分钟没下完),
# alpine 基础镜像小、且 apk 走阿里云源可在 10 秒内装好 python3 + 依赖。
# alpine:3.20 自带 python 3.12.13,与 slim 同小版本,行为一致。
# 若在国外或企业内网,改回下面注释的 slim 方案即可。
FROM python:3.12-slim FROM alpine:3.20
ENV PYTHONUNBUFFERED=1 \ ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \ PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
TZ=Asia/Shanghai \ TZ=Asia/Shanghai \
FX_DATA_DIR=/app/data \ FX_DATA_DIR=/app/data \
FX_CONFIG=/app/config.yaml FX_CONFIG=/app/config.yaml
RUN apt-get update \ # apk 走阿里云镜像(默认 dl-cdn 在国内很慢)
&& apt-get install -y --no-install-recommends tzdata ca-certificates curl \ RUN sed -i 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories \
&& rm -rf /var/lib/apt/lists/* \ && apk add --no-cache python3 py3-requests py3-yaml tzdata curl \
&& useradd --create-home --uid 10001 app && adduser -D -u 10001 app
WORKDIR /app WORKDIR /app
# 国内构建走镜像源;海外或企业内网可 --build-arg PIP_INDEX_URL=https://pypi.org/simple/
ARG PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
ARG PIP_TRUSTED_HOST=mirrors.aliyun.com
COPY requirements.txt ./
RUN pip install --no-cache-dir -i "$PIP_INDEX_URL" --trusted-host "$PIP_TRUSTED_HOST" -r requirements.txt
COPY fengxiang ./fengxiang COPY fengxiang ./fengxiang
COPY order_monitor.py fetch_orders.py push_latest_order.py healthcheck.py ./ COPY order_monitor.py fetch_orders.py push_latest_order.py healthcheck.py ./
RUN mkdir -p /app/data && chown -R app:app /app RUN mkdir -p /app/data && chown -R app:app /app
USER app USER app
WORKDIR /app
EXPOSE 8089 EXPOSE 8089
# 健康检查看的是"是否还在轮询",不是端口是否通 # 健康检查看的是"是否还在轮询",不是端口是否通
HEALTHCHECK --interval=60s --timeout=10s --start-period=60s --retries=3 \ HEALTHCHECK --interval=60s --timeout=10s --start-period=60s --retries=3 \
CMD ["python", "healthcheck.py"] CMD ["python3", "healthcheck.py"]
CMD ["python", "order_monitor.py"] CMD ["python3", "order_monitor.py"]
# ---------------------------------------------------------------------------
# 备选(Debian slim + pip,需要能顺畅访问 PyPI/国内镜像):
#
# FROM python:3.12-slim
# ARG PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
# ARG PIP_TRUSTED_HOST=mirrors.aliyun.com
# RUN apt-get update && apt-get install -y --no-install-recommends tzdata ca-certificates \
# && rm -rf /var/lib/apt/lists/* && useradd --create-home --uid 10001 app
# COPY requirements.txt ./
# RUN pip install --no-cache-dir -i "$PIP_INDEX_URL" --trusted-host "$PIP_TRUSTED_HOST" -r requirements.txt
# ---------------------------------------------------------------------------
+3
View File
@@ -62,6 +62,9 @@ docker compose ps # STATUS 应为 healthy
curl -s localhost:52100/healthz | python3 -m json.tool curl -s localhost:52100/healthz | python3 -m json.tool
``` ```
> 镜像基于 `alpine:3.20` + apk(阿里云源),构建约 10 秒。
> 官方 `python:3.12-slim` 在国内常卡在基础层下载,Dockerfile 末尾保留了切换回去的注释。
首次部署后必须在本地跑一次 `login.bat`(或 `fengxiang_scraper.py --upload`)把 Cookie 推上去, 首次部署后必须在本地跑一次 `login.bat`(或 `fengxiang_scraper.py --upload`)把 Cookie 推上去,
否则监控会一直停在「等待 Cookie」状态。 否则监控会一直停在「等待 Cookie」状态。