I’m having trouble getting Puppeteer to function correctly within a Docker environment. Even after manually installing Chrome, I’m receiving an error that indicates it cannot find the browser.
The error message states:
Could not find Chrome (ver. 133.0.6943.98). This can occur if either
1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or
2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).
Here is how I’ve set up my Docker configuration:
# Environment setup
FROM node:18 AS base
ENV NODE_ENV=development
ENV NODE_OPTIONS="--max-old-space-size=2048"
ENV PUPPETEER_CACHE_DIR="/root/.cache/puppeteer"
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
# Dependencies installation
FROM base AS dependencies
WORKDIR /application
RUN apt-get update && apt-get install -y wget gnupg curl \
&& 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 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
COPY package.json yarn.lock* .yarnrc.yml ./
COPY .yarn/releases ./.yarn/releases
RUN yarn install
RUN npx puppeteer browsers install chrome
# Application build
FROM base AS build
WORKDIR /application
COPY --from=dependencies /application/node_modules ./node_modules
COPY . .
RUN yarn build
EXPOSE 3000
ENV PORT=3000
CMD ["yarn", "start"]
When I enter the container shell, I cannot locate where Chrome was installed. What could I be missing?