Skip to content

Instantly share code, notes, and snippets.

@kettanaito
Last active January 29, 2025 10:33
Show Gist options
  • Save kettanaito/d0c9d0e44673353bdaf46148b8857efd to your computer and use it in GitHub Desktop.
Save kettanaito/d0c9d0e44673353bdaf46148b8857efd to your computer and use it in GitHub Desktop.
Puppeteer in πŸ‹ Docker

Puppeteeer in πŸ‹ Docker

...is a huge pain. After hours of searching through every possible snippet on the Internet I coulld find, this is the Dockerfile that finally worked for me. Let it bring you joy.

Note: This approach doesn't create a special previledged user, so you have to add --no-sandbox to the Puppeteer's browser args.

Usage

Dependencies

{
  "puppeteer": "^23.1.0"
}

Spawn the browser

import { launch } from 'puppeteer'

const browser = await launch({
  headless: true,
  args: [
    '--no-sandbox',
    '--disable-setuid-sandbox',
    '--disable-gpu',
    '--disable-software-rasterizer',
  ],
})
FROM node:22-slim as base
# Skip downloading Chromium as we are installing it manually.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
# Point Puppeteer at the manually installed executable.
ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/google-chrome"
# 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 gnupg wget -y && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
apt-get install google-chrome-stable -y --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
# The rest of your app...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment