return to old Dockerfile

This commit is contained in:
k
2026-06-14 23:28:40 +08:00
parent fa1700d9e8
commit 1ab553f778
+6 -14
View File
@@ -1,4 +1,6 @@
# ── Stage 1: build ─────────────────────────────────────────────────────────── # ── Stage 1: build ───────────────────────────────────────────────────────────
# Compiles native extensions (ckzg, asyncpg, cryptography) so the final image
# only carries the compiled .so files, not the build toolchain.
FROM python:3.11-slim AS builder FROM python:3.11-slim AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -10,23 +12,19 @@ WORKDIR /build
RUN pip install --no-cache-dir --upgrade pip wheel setuptools RUN pip install --no-cache-dir --upgrade pip wheel setuptools
COPY requirements.txt . COPY requirements.txt .
# 直接打包安装到标准的 site-packages 路径中,方便后面拷贝 RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
RUN pip install --no-cache-dir --user -r requirements.txt
# ── Stage 2: runtime ───────────────────────────────────────────────────────── # ── Stage 2: runtime ─────────────────────────────────────────────────────────
FROM python:3.11-slim FROM python:3.11-slim
# Only runtime shared libs needed (libpq for asyncpg, libgomp for numpy if used)
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 curl \ libpq5 curl \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# 【核心修改】直接从 builder 的用户目录下把装好的第三方库拷贝过来 # Copy compiled packages from builder
COPY --from=builder /root/.local /root/.local COPY --from=builder /install /usr/local
# 【核心修改】将拷贝过来的库路径加入到环境变量中,确保 Python 100% 能找到它们
ENV PATH=/root/.local/bin:$PATH
ENV PYTHONPATH=/root/.local/lib/python3.11/site-packages:$PYTHONPATH
WORKDIR /app WORKDIR /app
COPY . . COPY . .
@@ -35,12 +33,6 @@ RUN chmod +x entrypoint.sh
# Non-root user # Non-root user
RUN useradd -m appuser && chown -R appuser /app RUN useradd -m appuser && chown -R appuser /app
# 确保新创建的 appuser 也有权限读取拷贝过来的第三方库
RUN cp -R /root/.local /home/appuser/ && chown -R appuser:appuser /home/appuser/.local
ENV PATH=/home/appuser/.local/bin:$PATH
ENV PYTHONPATH=/home/appuser/.local/lib/python3.11/site-packages:$PYTHONPATH
USER appuser USER appuser
EXPOSE 8000 EXPOSE 8000