I’m stuck trying to get Puppeteer working in a Docker setup. Even though I’ve added Chrome installation to my Dockerfile, I keep getting an error message saying it can’t find Chrome.
Here’s what the error looks like:
Chrome (version 133.0.6943.98) not found. This might be because:
1. You didn't install browsers before running the script
2. Your cache path is wrong (currently set to /root/.cache/puppeteer)
I’ve set up my Dockerfile with Node 18, installed Chrome, and configured Puppeteer. I’ve even tried running npx puppeteer browsers install chrome
in the container.
But when I check inside the container, I can’t find Chrome anywhere. Any ideas what I’m missing or how to fix this? I’m pretty sure I’ve followed all the usual steps for setting up Puppeteer in Docker.
hey sparklingGem, have u tried using a custom chrome binary? sometimes the default one doesn’t play nice with docker. u can download a specific version and point puppeteer to it in ur code. might solve ur headache. good luck!
Have you considered using a pre-built Docker image specifically for Puppeteer? There are several available on Docker Hub that come with Chrome and all necessary dependencies pre-installed. This can save you a lot of trouble with configuration.
If you prefer to stick with your current setup, double-check your Dockerfile. Ensure you’re installing all required system dependencies for Chrome, not just Chrome itself. Also, verify that you’re using the correct Chrome path in your Puppeteer configuration.
Another thing to try is running Puppeteer with the --no-sandbox flag. This can sometimes resolve issues in containerized environments. Just be aware of the security implications if you’re processing untrusted content.
Lastly, make sure your Docker container has sufficient resources allocated, especially if you’re running headless Chrome. Limited memory or CPU can sometimes cause unexpected errors.
I’ve run into this issue before, and it can be frustrating. One thing that worked for me was explicitly setting the Chrome executable path in my Puppeteer configuration.
Try adding this to your Puppeteer launch options:
const browser = await puppeteer.launch({
executablePath: '/usr/bin/google-chrome',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
Also, make sure your Dockerfile is installing the necessary dependencies for Chrome. You might need to add something like:
RUN apt-get update && apt-get install -y \
wget \
gnupg \
ca-certificates \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& 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 -y google-chrome-stable
These steps helped me get Puppeteer running smoothly in Docker. Let me know if you need any more details!