I'm trying to launch puppeteer inside a podman container but as I read online this isn't really straightforward. I mainly followed this guide but I get the following error which seems pretty contradictory given that I'm launching puppeteer with the no-sandbox arg:
Error generating PDF: Error: Failed to launch the browser process! undefined
[119:119:0122/132051.165237:ERROR:zygote_host_impl_linux(101)]
Running as root without --no-sandbox is not supported. See .
I set up my dockerfile like this to install google chrome manually inside the container:
FROM node:20 AS build-frontend
WORKDIR /app/client
COPY env.txt /app/client/env.txt
COPY client/ .
RUN grep '^VITE' /app/client/env.txt > /app/client/.env && npm install && npm run build
FROM node:20 as build-backend
# Set up working directory
WORKDIR /app
# Copy environment and server files
COPY env.txt /app/env.txt
WORKDIR /app/server
COPY server/ .
COPY --from=build-frontend /app/client/dist ./public
COPY ssl/server.crt /app/ssl/server.crt
COPY ssl/server.key /app/ssl/server.key
# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer.
RUN apt-get update && apt-get install -y curl gnupg --no-install-recommends \
&& curl --location --silent .pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] / stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN DEBIAN_FRONTEND="noninteractive" && grep '^REACT_APP' /app/env.txt > /app/.env && apt-get update && \
apt-get install -y python3 python3-pip python3-venv nginx nginx-common tzdata && npm install && \
python3 -m venv /venv && /venv/bin/pip install --upgrade pip && /venv/bin/pip install -r requirements.txt
# Happens after install of nginx, so that there's no conflict.
COPY nginx.conf /etc/nginx/nginx.conf
# Expose HTTP port for redirection to 443
EXPOSE 80 443
CMD ["node", "server.js"]
I set up the puppeteer launch accordingly to disable sandbox mode and link to the installed chrome:
app.post('/api/generate-pdf', async (req, res) => {
...
try {
const browser = await puppeteer.launch({
executablePath: '/usr/bin/google-chrome-stable', // Path to Google Chrome
defaultViewport: null,
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage', // Reduce the reliance on /dev/shm
'--disable-gpu', // Optional: Useful for some environments
'--disable-software-rasterizer']
});
In conclusion, this is how I build the container. I add the --platform linux/amd64
parameter as suggested by the guide because the google chrome distribution is compatible with amd64 architecture:
podman build --platform linux/amd64 --squash -t cc-niap .