C
C#3mo ago
Alex

✅ Run PuppeteerSharp in Docker Container

I have an endpoint that creates PDFs using PuppeteerSharp. I work fine locally because it can automatically download Chromium. The opposite in the Docker Container, it tells me that no executable chromium found. Is there a way to pre download?
FROM mcr.microsoft.com/dotnet/sdk:8.0 as build
WORKDIR /App

COPY . ./

RUN dotnet restore
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /App
COPY --from=build /App/out .
ENTRYPOINT ["dotnet", "Vocabify.API.dll"]
FROM mcr.microsoft.com/dotnet/sdk:8.0 as build
WORKDIR /App

COPY . ./

RUN dotnet restore
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /App
COPY --from=build /App/out .
ENTRYPOINT ["dotnet", "Vocabify.API.dll"]
6 Replies
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Alex
Alex3mo ago
let's see if it works I've tried the way it installs on Linux
RUN apt-get update && apt-get install -y wget gnupg
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update && apt-get install -y google-chrome-stable
RUN rm -rf /var/lib/apt/lists/*

ENV PUPPETEER_EXECUTABLE_PATH "/usr/bin/google-chrome-stable"
RUN apt-get update && apt-get install -y wget gnupg
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update && apt-get install -y google-chrome-stable
RUN rm -rf /var/lib/apt/lists/*

ENV PUPPETEER_EXECUTABLE_PATH "/usr/bin/google-chrome-stable"
But if I look into the container there is nothing along this path, let me check if there any docker specific guides
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Alex
Alex3mo ago
Maybe they have it, I'll check
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Alex
Alex3mo ago
I build it with docker compose and if there is error it shows it in console and process stops. That's why I'm not sure why it's not working for me, while in the guide it works. Now it gives me exception that it's searching chrome inside /App/Chrome/Linux-124.0.6367.60/chrome-linux64/chrome and can't find This configuration worked for me Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:8.0 as build

WORKDIR /App

COPY . ./

RUN dotnet restore
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0

# Install dependencies for puppeteer
RUN apt-get update && \
apt-get install -y \
wget \
gnupg2 \
apt-transport-https \
ca-certificates \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libcups2 \
libdbus-1-3 \
libgdk-pixbuf2.0-0 \
libnspr4 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
xdg-utils \
libgbm1 \
libxcb-dri3-0 \
libxss1 && \
rm -rf /var/lib/apt/lists/*


WORKDIR /App
COPY --from=build /App/out .
ENTRYPOINT ["dotnet", "Vocabify.API.dll"]
FROM mcr.microsoft.com/dotnet/sdk:8.0 as build

WORKDIR /App

COPY . ./

RUN dotnet restore
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0

# Install dependencies for puppeteer
RUN apt-get update && \
apt-get install -y \
wget \
gnupg2 \
apt-transport-https \
ca-certificates \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libcups2 \
libdbus-1-3 \
libgdk-pixbuf2.0-0 \
libnspr4 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
xdg-utils \
libgbm1 \
libxcb-dri3-0 \
libxss1 && \
rm -rf /var/lib/apt/lists/*


WORKDIR /App
COPY --from=build /App/out .
ENTRYPOINT ["dotnet", "Vocabify.API.dll"]
File.cs
await new BrowserFetcher().DownloadAsync();
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
Args = new string[] { "--no-sandbox", "--disable-setuid-sandbox" }
});

Console.WriteLine("Browser launched successfully.");
await new BrowserFetcher().DownloadAsync();
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
Args = new string[] { "--no-sandbox", "--disable-setuid-sandbox" }
});

Console.WriteLine("Browser launched successfully.");
Want results from more Discord servers?
Add your server
More Posts