From d76c1cad8738f87ab6e132d47e4a7605f277cfa3 Mon Sep 17 00:00:00 2001 From: yuming Date: Mon, 27 Apr 2026 09:29:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(docker):=20=E6=94=B9=E7=94=A8=20npx=20playw?= =?UTF-8?q?right=20install=20=E4=B8=8B=E8=BD=BD=20Chromium=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E8=B7=AF=E5=BE=84=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前用 dotnet tool 方式被 || true 吞掉错误导致 /ms-playwright 不存在。 改为在 builder 阶段装 Node.js 18 后用 npx playwright@1.44.0 install 下载, 路径可靠,复制到 final 阶段不再报错。 Co-Authored-By: Claude Sonnet 4.6 --- Dockerfile.prod | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Dockerfile.prod b/Dockerfile.prod index f0c93f6..0289454 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -23,6 +23,12 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS backend-builder WORKDIR /src +# 安装 Node.js 18(用于 npx playwright install,最可靠的方式) +RUN apt-get update && apt-get install -y curl && \ + curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ + apt-get install -y nodejs && \ + rm -rf /var/lib/apt/lists/* + COPY *.csproj ./ RUN dotnet restore dy.net.csproj @@ -33,18 +39,15 @@ COPY --from=frontend-builder /app/frontend/dist ./app/dist RUN dotnet publish dy.net.csproj -c Release -o /app/publish -# 安装 Playwright CLI 并下载 Chromium 浏览器到固定路径 +# 用 npx 下载 Playwright Chromium 到固定路径 ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright -RUN dotnet tool install --global Microsoft.Playwright.CLI --version 1.44.0 2>/dev/null || true && \ - /root/.dotnet/tools/playwright install chromium --with-deps 2>/dev/null || \ - dotnet /app/publish/playwright.ps1 install chromium 2>/dev/null || true +RUN npx -y playwright@1.44.0 install chromium # 第三阶段:运行镜像 FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final WORKDIR /app -# 设置时区 ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone @@ -68,7 +71,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ fonts-liberation \ && rm -rf /var/lib/apt/lists/* -# 从构建阶段复制应用和浏览器 COPY --from=backend-builder /app/publish . COPY --from=backend-builder /ms-playwright /ms-playwright