Created
December 9, 2025 12:55
-
-
Save walokra/59a43036c851aae9d0de309f4633185a to your computer and use it in GitHub Desktop.
Multistage Dockerfile for Playwright and Puppeteer with Chromium and pnpm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Base image | |
| # | |
| FROM public.ecr.aws/docker/library/node:24-alpine AS stage-base | |
| ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0 | |
| # Install corepack and pnpm | |
| RUN npm install --global corepack@latest && \ | |
| corepack enable pnpm && \ | |
| corepack prepare --activate pnpm@latest-10 | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy dependencies information to WORKDIR | |
| COPY package.json pnpm-lock* ./ | |
| COPY .npmrc . | |
| # Install dependencies | |
| RUN pnpm install | |
| # | |
| # Build stage | |
| # | |
| FROM stage-base AS stage-build | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy from previous stage node_modules | |
| COPY --from=stage-base /app/node_modules ./node_modules | |
| # Copy source code | |
| COPY . . | |
| # Build the project | |
| RUN pnpm build | |
| # | |
| # Server stage | |
| # | |
| FROM public.ecr.aws/docker/library/node:24-alpine | |
| # Set working directory | |
| WORKDIR /app | |
| ENV NODE_ENV=production | |
| # From https://github.com/jlandure/alpine-chrome/blob/master/with-playwright/Dockerfile | |
| ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 | |
| ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser | |
| # Install necessary packages for Playwright in runtime image | |
| RUN apk add --no-cache \ | |
| chromium-swiftshader \ | |
| nss \ | |
| freetype \ | |
| harfbuzz \ | |
| ca-certificates \ | |
| ttf-freefont | |
| COPY --chown=node:node --from=stage-build /app/dist . | |
| COPY --chown=node:node --from=stage-build /app/node_modules ./node_modules | |
| # Run container with non-root user | |
| USER node | |
| ENV CHROME_BIN=/usr/bin/chromium-browser \ | |
| CHROME_PATH=/usr/lib/chromium/ | |
| # Run the app | |
| CMD node index.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Base image | |
| # | |
| FROM public.ecr.aws/docker/library/node:24-alpine AS stage-base | |
| ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0 | |
| # Install corepack and pnpm | |
| RUN npm install --global corepack@latest && \ | |
| corepack enable pnpm && \ | |
| corepack prepare --activate pnpm@latest-10 | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy dependencies information to WORKDIR | |
| COPY package.json pnpm-lock* ./ | |
| COPY .npmrc . | |
| # Install dependencies | |
| RUN pnpm install | |
| # | |
| # Build stage | |
| # | |
| FROM stage-base AS stage-build | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy from previous stage node_modules | |
| COPY --from=stage-base /app/node_modules ./node_modules | |
| # Copy source code | |
| COPY . . | |
| # Build the project | |
| RUN pnpm build | |
| # | |
| # Server stage | |
| # | |
| FROM public.ecr.aws/docker/library/node:24-alpine | |
| # Set working directory | |
| WORKDIR /app | |
| ENV NODE_ENV=production | |
| # Install Puppeteer dependencies | |
| # See suppoeted browser versions at https://pptr.dev/supported-browsers | |
| RUN apk add --no-cache \ | |
| chromium=139.0.7258.154-r0 \ | |
| nss \ | |
| freetype \ | |
| harfbuzz \ | |
| ca-certificates \ | |
| ttf-freefont | |
| # Tell Puppeteer to skip installing Chrome. We'll be using the installed package. | |
| ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true | |
| ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser | |
| COPY --chown=node:node --from=stage-build /app/dist . | |
| COPY --chown=node:node --from=stage-build /app/node_modules ./node_modules | |
| # Run container with non-root user | |
| USER node | |
| # Run the app | |
| CMD node index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment