Search code examples
.netdockerdockerfileplaywrightplaywright-sharp

Cannot run PlayWright inside docker image


I`m trying to create .net 5.0 docker image with playwright. This is my DockerFile:

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 dotnet add package Microsoft.Playwright
RUN dotnet build "Agent.csproj" -c Release -o /app/build
RUN npx playwright install

But once I run inside my image command dotnet run Agent it gives me following error:

Executable doesn't exist at /root/.cache/ms-playwright/chromium-907428/chrome-linux/chrome
Please run the following command to download new browsers:              
║                                                                         
║     npx playwright install

Even though my dockerfile contains RUN npx playwright install seems like its not installing it. When I will remove it from my dockerfile and execute it manualy on running image it seems to be ok. Any ideas how I can execute properly playwright install using dockerfile?


Solution

  • My problem was that I have installed different version of chromium vs playwright