Issue with updating dockerfile to use Microsoft.Playwright
See original GitHub issueI’ve tried everything I can think of from the docs and googling to update this Dockerfile to properly install Playwright when building, but I can’t seem to get playwright install
to work. It may be due to my only intermediate knowledge of Docker.
Can anyone tell me what an updated Dockerfile would look like? I got past the battle of getting dotnet tool
commands to work. There also seems to be an is sue with the tools path inside a Docker, but even when I got that fixed playwright install
would still fail because I am building the project in a source image.
Current Dockerfile I am using with <PackageReference Include="PlaywrightSharp" Version="0.192.0" />
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY .nuget/NuGet.Config ./
# Copy everything else and build
COPY . ./
ARG RELEASE_CONFIG=Debug
RUN dotnet restore --configfile .nuget/NuGet.Config
RUN dotnet publish --framework net5.0 Foo.Bar/Foo.Bar.csproj -c ${RELEASE_CONFIG} -o out \
&& mkdir /app/out/.playwright \
&& cp -r /app/Foo.Bar/bin/${RELEASE_CONFIG}/net5.0/.playwright/unix /app/out/.playwright
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
ARG DEFAULT_ENV=DEV
ENV ASPNETCORE_ENVIRONMENT=${DEFAULT_ENV}
WORKDIR /app
COPY --from=build-env /app/out/ .
RUN apt-get update \
&& apt-get install libglib2.0-0 -y \
&& apt-get install libnss3 -y \
&& apt-get install libnspr4 -y \
&& apt-get install libatk1.0-0 -y \
&& apt-get install libatk-bridge2.0-0 -y \
&& apt-get install libcups2 -y \
&& apt-get install libdrm2 -y \
&& apt-get install libdbus-1-3 -y \
&& apt-get install libexpat1 -y \
&& apt-get install libxcb1 -y \
&& apt-get install libxkbcommon0 -y \
&& apt-get install libx11-6 -y \
&& apt-get install libxcomposite1 -y \
&& apt-get install libxdamage1 -y \
&& apt-get install libxext6 -y \
&& apt-get install libxfixes3 -y \
&& apt-get install libxrandr2 -y \
&& apt-get install libgbm1 -y \
&& apt-get install libgtk-3-0 -y \
&& apt-get install libpango-1.0-0 -y \
&& apt-get install libcairo2 -y \
&& apt-get install libasound2 -y \
&& apt-get install libatspi2.0-0 -y \
&& apt-get install libxshmfence1 -y \
&& .playwright/unix/native/playwright.sh install
CMD ["dotnet","Foo.Bar.dll"]
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (7 by maintainers)
Top Results From Across the Web
Cannot run PlayWright inside docker image
Try adding an environment variable: PLAYWRIGHT_BROWSERS_PATH="/ms-playwright" Hope to help you.
Read more >Docker
If the Playwright version in your Docker image does not match the version in your project/tests, Playwright will be unable to locate browser...
Read more >Playwright in Docker not working: Microsoft. ...
The error came from me not correctly understanding Docker stages. Here a fixed Dockerfile, where I installed Playwright in the base stage:
Read more >How To Run End-to-End Tests Using Playwright and Docker
In this tutorial, you will set up an environment to use Playwright with Typescript for end-to-end testing, write and execute the tests, ...
Read more >Playwright Docker Tutorial: A Step-by-Step Guide with ...
This Playwright Docker tutorial deep dives into how Playwright and Docker can be used together to simplify browser testing and improve the reliability...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This Dockerfile works (and the same solution works with the release version of the CLI/LIB even though the below is using the previous). It still has to reference the playwright install via the full path because the playwright executable is not being put in the path when the global tool is installed.
You can also ignore the final RUN command, this is just something I had to do because of the interim copy and some permissions shenanigans caused by the security in my org’s k8s cluster.
I’m also having the same issue. Anyone managed to find a solution?