question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with updating dockerfile to use Microsoft.Playwright

See original GitHub issue

I’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:closed
  • Created 2 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tehmufifnmancommented, Jul 10, 2021

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.

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app

# Install Playwright CLI
RUN dotnet tool install --global Microsoft.Playwright.CLI --version 1.0.1-next-1

# 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 FooService/FooService.csproj -c ${RELEASE_CONFIG} -o out
ENV PLAYWRIGHT_BROWSERS_PATH=/app/out/browsers
RUN /root/.dotnet/tools/playwright install

# 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

RUN chmod +rx,o+rx /app/.playwright \
    && chmod +rx,o+rx /app/.playwright/node \
    && chmod +rx,o+rx /app/.playwright/node/linux \
    && chmod +rx,o+rx /app/.playwright/node/linux/playwright.sh

CMD ["dotnet","FooService.dll"]
1reaction
Jaxtercommented, Jun 24, 2021

I’m also having the same issue. Anyone managed to find a solution?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found