admin管理员组

文章数量:1123404

I am trying to run Puppeteer using Firefox in a Docker container. Below is my Dockerfile:

# Use the official Node.js Docker image as the base image
FROM node:slim

# We don't need the standalone Chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# Install Firefox and necessary libraries
RUN apt-get update && apt-get install -y \
    wget \
    gnupg \
    firefox-esr \
    libgtk-3-0 \
    libdbus-glib-1-2 \
    libxt6 \
    libasound2 \
    libnss3 \
    libxss1 \
    xdg-utils \
    xvfb \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to the container
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code to the container
COPY . .

# Environment variables
ENV HEADLESS true
ENV DEFAULT_PUPPETEER_TIMEOUT 15000

# Command to start the application
CMD ["npm", "start"]

When I run the container, I get the following error:

`error: Error during replayJson execution: Failed to launch the browser process!
Error: no DISPLAY environment variable specified`

The HEADLESS environment variable is set to true. I also tried starting Xvfb in the container by adding the following to the Dockerfile:

`CMD ["sh", "-c", "Xvfb :99 -screen 0 1920x1080x24 & npm start"]`

However, the issue persists.

How can I resolve the no DISPLAY environment variable specified error for Puppeteer with Firefox in Docker?

本文标签: