title: Failed to launch Base! /app/.local-chromium/Linux-706915/chrome-linux/chrome: ... libX11.so.6
body: <p>I have an instance of puppeteer-sharp running on ASP.NET Core 3.1 that works fine locally. For deployment, it gets built in a docker container and deployed to a K8 dev cluster. The docker container builds fine, but the app fails at runtime with the error <code>Failed to launch Base! /app/.local-chromium/Linux-706915/chrome-linux/chrome: error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directory</code> when trying to use puppeteer-sharp.</p>
  <p>From the following resources, I pieced together the below dockerfile. I'm still fairly inexperienced with docker so imagine it's something wrong with the config, but I'm open to suggestions!</p>
  <p><strong>Resources used:</strong></p>
  <ul>
  <li><a href="http://www.hardkoded.com/blog/puppeteer-sharp-docker" rel="noreferrer">http://www.hardkoded.com/blog/puppeteer-sharp-docker</a></li>
  <li><a href="https://techoverflow.net/2018/06/05/how-to-fix-puppetteer-error-while-loading-shared-libraries-libx11-xcb-so-1-cannot-open-shared-object-file-no-such-file-or-directory/" rel="noreferrer">https://techoverflow.net/2018/06/05/how-to-fix-puppetteer-error-while-loading-shared-libraries-libx11-xcb-so-1-cannot-open-shared-object-file-no-such-file-or-directory/</a></li>
  <li><a href="https://stackoverflow.com/questions/58746052/docker-nodejs-puppeteer2-0-0-how-do-fix-failed-to-launch-chrome-issue">Docker NodeJS Puppeteer@2.0.0 - How do fix Failed to launch chrome! issue</a> (headless = false had no effect)</li>
  </ul>
  <p><strong>Dockerfile:</strong></p>
  <pre><code>#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
  
  FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
  WORKDIR /app
  EXPOSE 80
  EXPOSE 443
  
  
  FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
  WORKDIR /src
  
  #####################
  #PUPPETEER RECIPE
  #####################
  # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
  # Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
  # installs, work.
  ARG CHROME_VERSION=&quot;81.0.4044.138-1&quot;
  RUN apt-get update &amp;&amp; apt-get -f install &amp;&amp; apt-get -y install apt-utils wget gnupg2 
  RUN apt-get -f install &amp;&amp; apt-get -y install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils
  RUN wget --no-verbose -O /tmp/chrome.deb http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \
  &amp;&amp; apt-get update \
  &amp;&amp; apt-get install -y /tmp/chrome.deb --no-install-recommends --allow-downgrades \
  &amp;&amp; rm /tmp/chrome.deb
  
  # NOTE: REMOVED THIS WHILST DEBUGGING - D
  # Add user, so we don't need --no-sandbox.
  # same layer as npm install to keep re-chowned files from using up several hundred MBs more space    
  #RUN groupadd -r pptruser &amp;&amp; useradd -r -g pptruser -G audio,video pptruser \
      #&amp;&amp; mkdir -p /home/pptruser/Downloads \
      #&amp;&amp; chown -R pptruser:pptruser /home/pptruser
  #
  ## Run everything after as non-privileged user.
  #
  #USER pptruser
  
  ENV PUPPETEER_EXECUTABLE_PATH &quot;/usr/bin/google-chrome-unstable&quot;
  
  #####################
  #END PUPPETEER RECIPE
  #####################
  
  
  COPY [&quot;ProjectName.Core/ProjectName.Core.csproj&quot;, &quot;ProjectName.Core/&quot;]
  RUN dotnet restore &quot;ProjectName.Core/ProjectName.Core.csproj&quot;
  COPY . .
  WORKDIR &quot;/src/ProjectName.Core&quot;
  RUN dotnet build &quot;ProjectName.Core.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;ProjectName.Core.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;ProjectName.Core.dll&quot;]
  </code></pre>
  <p><strong>Code Implementation:</strong></p>
  <pre><code>        public static async Task&lt;Stream&gt; GeneratePdfFromHtml(string html, List&lt;string&gt; styleUrls = null)
          {
              await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
  
              var browser = await Puppeteer.LaunchAsync(new LaunchOptions
              {
                  Headless = true                
              });
  
              using (var page = await browser.NewPageAsync())
              {
                  await page.SetContentAsync(html);
  
                  if(styleUrls != null)
                      foreach (var url in styleUrls)
                      {
                          await page.AddStyleTagAsync(url);
                      }
  
                  return await page.PdfStreamAsync();                
              }
          }
  </code></pre>
  <p>The resources using Docker all target .NET Core 2.0 so I don't know if that has anything to do with it. The fact that it runs fine outside of a Docker environment suggests the .NET Core version isn't the problem and is more likely a step in the dockerfile itself.</p>