Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Puppeteer within a docker container

I'm pretty new to the node.js world.

I can't get puppeteer to run successfully inside a container. I've tried manually installing Chrome and its drivers to no avail.

I've found that puppeteer provides a docker image for testing purposes which should have all the chrome dependencies installed, but I can't get it work.

Here is my dockerfile:

FROM buildkite/puppeteer:latest

EXPOSE 8181

# Set the working directory
WORKDIR /app

# Install app dependencies

COPY ./backend .

RUN npm install

COPY . .

CMD ["npm", "test"]

This is my scripts section in package.json

"scripts": {
    "start": "node server.js",
    "test": "mocha ./tests/test_root.js ./tests/test_dataset.js ./tests/test_frontend.js"
  },

With this I get Error: Cannot find module 'node:http'

Can anyone help with this, or am I barking up the wrong tree!

Thanks

like image 958
WhatTheWhat Avatar asked Sep 03 '25 16:09

WhatTheWhat


1 Answers

The solution was to try and install the drivers. This did it:

FROM node:20

EXPOSE 8181

# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer.
RUN apt-get update && apt-get install gnupg wget -y && \
  wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
  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 google-chrome-stable -y --no-install-recommends && \
  rm -rf /var/lib/apt/lists/*

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install
RUN npm install --save-dev

COPY . .

CMD npm test
like image 91
WhatTheWhat Avatar answered Sep 05 '25 11:09

WhatTheWhat