How to run Puppeteer in a Docker container?

To run Puppeteer in a Docker container, you can follow these steps:

  1. Create a Dockerfile: Create a Dockerfile in your project directory with the following contents:
FROM node:14 RUN apt-get update && apt-get install -y \ gconf-service \ libasound2 \ libatk1.0-0 \ libcups2 \ libdbus-1-3 \ libgconf-2-4 \ libgtk-3-0 \ libnspr4 \ libnss3 \ libx11-xcb1 \ libxcomposite1 \ libxdamage1 \ libxrandr2 \ xdg-utils WORKDIR /app COPY package.json . COPY package-lock.json . RUN npm install COPY . . CMD ["node", "your_script.js"]
  1. Build the Docker image: Run the following command in your terminal to build the Docker image:
docker build -t puppeteer-docker .
  1. Run the Docker container: Once the Docker image is built, you can run a Docker container using the following command:
docker run -it puppeteer-docker

This will start a Docker container with Puppeteer installed, and it will run the script defined in your Dockerfile (Replace "your_script.js" with the name of your Puppeteer script).

That's it! You have successfully run Puppeteer in a Docker container.