I’m having trouble with Puppeteer in a Docker setup. I’m trying to create PDFs and also use Selenium for some automation stuff. Here’s what I’ve got in my Dockerfile:
When I run this on my EC2 instance, I get an error saying it can’t find Chrome. Any ideas on how to fix this? I’m not sure if it’s a setup issue or something else.
The issue you’re encountering is likely due to Puppeteer not finding a compatible Chrome installation in your Docker environment. Your Dockerfile is set up for Firefox and Selenium, but Puppeteer requires Chrome.
To resolve this, you’ll need to install Chromium in your Docker image. Modify your Dockerfile to include:
RUN apk add --no-cache chromium
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
I’ve dealt with similar Puppeteer issues in Docker before. One thing to note is that Alpine-based images can be tricky with Puppeteer. Instead of struggling with Alpine, I’d recommend switching to a Debian-based image like node:16-slim. It’s still lightweight but more compatible with Puppeteer out of the box.
In your Dockerfile, you’d then use:
RUN apt-get update && apt-get install -y chromium
And set the environment variable:
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
This approach has worked well for me in production. It avoids some of the headaches that come with Alpine while still keeping the image relatively small. Just remember to adjust your package manager commands from apk to apt-get when you make the switch.