skip to Main Content

I have a .net dashboard application where a user can export the current page as pdf via playwright.
This works locally, however, when I run the application in Docker I get this error:


    Microsoft.Playwright.PlaywrightException: Executable doesn't exist at /root/.cache/ms-playwright/chromium-1005/chrome-linux/chrome
     ╔════════════════════════════════════════════════════════════╗
     ║ Looks like Playwright was just installed or updated.       ║
     ║ Please run the following command to download new browsers: ║
     ║                                                            ║
     ║     pwsh binDebugnetXplaywright.ps1 install             ║
     ║                                                            ║
     ║ <3 Playwright Team                                         ║
     ╚════════════════════════════════════════════════════════════╝

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0-focal  AS build
WORKDIR /src
COPY ["Dashboard/Dashboard.csproj", "Dashboard/"]
RUN dotnet restore "Dashboard/Dashboard.csproj"
COPY . .
WORKDIR "/src/Dashboard"
RUN dotnet add package Microsoft.Playwright
RUN dotnet build "Dashboard.csproj" -c Release -o /app/build
RUN dotnet tool update --global PowerShell
RUN pwsh /app/build/playwright.ps1 install --with-deps
FROM build AS publish
RUN dotnet publish "Dashboard.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Dashboard.dll"]

3

Answers


  1. Chosen as BEST ANSWER

    The error came from me not correctly understanding Docker stages. Here a fixed Dockerfile, where I installed Playwright in the base stage:

    FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
    RUN apt-get update
    RUN apt-get -y install curl gnupg
    RUN curl -sL https://deb.nodesource.com/setup_16.x  | bash -
    RUN apt-get -y install nodejs
    RUN npx playwright install
    RUN apt-get update && apt-get install -y --no-install-recommends 
        fonts-liberation
        libasound2
        libatk-bridge2.0-0
        libatk1.0-0
        libatspi2.0-0
        libcairo2
        libcups2
        libdbus-1-3
        libdrm2
        libgbm1
        libglib2.0-0
        libgtk-3-0
        libnspr4
        libnss3
        libpango-1.0-0
        libx11-6
        libxcb1
        libxcomposite1
        libxdamage1
        libxext6
        libxfixes3
        libxrandr2
    WORKDIR /app
    
    FROM mcr.microsoft.com/dotnet/sdk:6.0-focal  AS build
    WORKDIR /src
    COPY ["Dashboard/Dashboard.csproj", "Dashboard/"]
    RUN dotnet restore "Dashboard/Dashboard.csproj"
    COPY . .
    WORKDIR "/src/Dashboard"
    RUN dotnet build "Dashboard.csproj" -c Release -o /app/build
    FROM build AS publish
    RUN dotnet publish "Dashboard.csproj" -c Release -o /app/publish
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "Dashboard.dll"]
    

  2. Add the blow line after COPY –from=publish /app/publish .

    RUN chown -R pwuser:pwuser /app
    
    Login or Signup to reply.
  3. For anyone else, can find in document

    After build success, have playwright.ps1 file created, just run it with powershell:

    # dir: /your_source_folder
    powershell.exe bin/Debug/netX/playwright.ps1 install
    # or pwsh bin/Debug/netX/playwright.ps1 install
    

    Or you can install special browser, like chrome, firefox:

    powershell.exe bin/Debug/netX/playwright.ps1 install firefox
    powershell.exe bin/Debug/netX/playwright.ps1 install chrome
    

    Cache folders:

    Windows: %USERPROFILE%AppDataLocalms-playwright
    MacOS: ~/Library/Caches/ms-playwright
    Linux: ~/.cache/ms-playwright
    

    And add to "Post-build event" into csproj:

    powershell.exe -Command $(TargetDir)playwright.ps1 install firefox;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search