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
The error came from me not correctly understanding Docker stages. Here a fixed Dockerfile, where I installed Playwright in the base stage:
Add the blow line after COPY –from=publish /app/publish .
For anyone else, can find in document
After build success, have playwright.ps1 file created, just run it with powershell:
Or you can install special browser, like chrome, firefox:
Cache folders:
And add to "Post-build event" into csproj: