I’m having issues getting Puppeteer to work properly in a Docker setup. Even though I installed Chrome manually based on various guides, I keep getting this error message:
Chrome browser not found (version 133.0.6943.98). This error happens when:
1. Browser installation wasn't completed before script execution (try `npx puppeteer browsers install chrome`)
2. Cache directory is misconfigured (current path: /root/.cache/puppeteer)
Check the configuration guide for more details.
Here’s my Docker configuration:
# Phase 1: Set environment variables
#######################################
FROM node:18 AS environment
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"
# Skip automatic Chromium download
# Phase 2: Install dependencies
#######################################
FROM environment 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 files for optimal caching
COPY package.json yarn.lock* .yarnrc.yml ./
COPY .yarn/releases ./.yarn/releases
# Install project dependencies
RUN npm install
# Install Chrome for Puppeteer
RUN npx puppeteer browsers install chrome
# Phase 3: Application build
#######################################
FROM environment AS build
WORKDIR /application
# Import dependencies from previous stage
COPY --from=dependencies /application/node_modules ./node_modules
COPY . .
# Compile application
RUN npm run build
EXPOSE 3000
ENV PORT=3000
CMD ["npm", "start"]
When I access the container shell, I can’t find where Chrome got installed. What am I doing wrong here?