I have build a website scraper using Puppeteer and Node.js and now i want to dockerize it. I’ve tried multiple ways to tackle this, but encountering issue when puppeteer tries to start the browser for scraping.
My current basic Dockerfile without Puppeteer or any other dependencies:
I’ve tried multiple ways to update this Dockerfile in every sense (adding chrome, puppeteer) but doesn’t work
# Use Node.js runtime as the base image
FROM node:18
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Expose the port the app runs on
EXPOSE 8080
# Command to run the application
CMD ["node", "scraper.js"]
Code :
Snippet which triggers/launches the browser
// Launch browser
const browser = await launch({ headless: true, defaultViewport: null });
Can someone help me here how can i tackle this to work ideally ?
Tried every possible way from here, here and here