无法启动剧作家铬

Cannot launch playwright chromium

我正在尝试与剧作家一起创建 .net 5.0 docker 图像,我的图像构建正确但是当我 运行 我的应用程序使用

dotnet run Agent 它失败于:

 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 
            {
                Headless = false,
                Args = new[] { "--disable-dev-shm-usage" }
            });

收到错误:

    Unhandled exception. Microsoft.Playwright.PlaywrightException: Browser closed.
==================== Browser output: ====================
[pid=226][err]   "switch-12" = "--allow-pre-commit-input"
[pid=226][err]   "switch-11" = "--disable-features=ImprovedCookieControls,LazyFrameLoading,Globa"
[pid=226][err]   "switch-10" = "--disable-extensions"
[pid=226][err]   "switch-9" = "--disable-dev-shm-usage"
[pid=226][err]   "switch-8" = "--disable-default-apps"
[pid=226][err]   "switch-7" = "--disable-component-extensions-with-background-pages"
[pid=226][err]   "switch-6" = "--disable-client-side-phishing-detection"
[pid=226][err]   "switch-5" = "--disable-breakpad"
[pid=226][err]   "switch-4" = "--disable-backgrounding-occluded-windows"
[pid=226][err]   "switch-3" = "--disable-background-timer-throttling"
[pid=226][err]   "switch-2" = "--enable-features=NetworkService,NetworkServiceInProcess"
[pid=226][err]   "switch-1" = "--disable-background-networking"
[pid=226][err]   "num-switches" = "31"
[pid=226][err]   "osarch" = "x86_64"
[pid=226][err]   "pid" = "226"
[pid=226][err]   "ptype" = "browser"
[pid=226][err]
[pid=226][err] [1028/195405.736318:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[pid=226][err] [1028/195405.736388:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)

您可以在下面找到我的 DockerFile,我也在为我的 docker 图像手动安装缺少的依赖项。

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/runtime:5.0-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["Agent.csproj", "Agent/"]
RUN dotnet restore "Agent/Agent.csproj"
COPY . "/src/Agent"
WORKDIR "/src/Agent"
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -yq nodejs build-essential
RUN npm install -g npm
RUN apt-get install -y gstreamer1.0-libav libnss3-tools libatk-bridge2.0-0 libcups2-dev libxkbcommon-x11-0 libxcomposite-dev libxrandr2 libgbm-dev libgtk-3-0
    
RUN dotnet add package Microsoft.Playwright --version 1.15.2
RUN dotnet build "Agent.csproj" -c Release -o /app/build
RUN npm add playwright-chromium@1.15.2

FROM build AS publish
RUN dotnet publish "Agent.csproj" -c Release -o /app/publish

EXPOSE 80 添加到我的 Dockerfile 解决了我的问题:)