Debian Docker K8s の Puppeteer/Chromium: "X11 接続を開けません。"

Debian Docker K8s の Puppeteer/Chromium:

これが私を狂わせています。人形劇の実行構成でヘッドレスChromeインスタンスを実行するのはそれほど難しいとは思わなかった。

エラーは次のとおりです。

# launching puppeteer with config {"args":["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage","--disable-accelerated-2d-canvas","--no-first-run","--no-zygote","--single-process","--disable-gpu","--headless"],"headless":true,"devtools":false,"timeout":90000,"executablePath":"/usr/bin/chromium","dumpio":true}
[0124/153812.589239:ERROR:browser_main_loop.cc(536)] Failed to open an X11 connection.
[0124/153812.590155:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
xcb_connection_has_error() returned true
[0124/153812.592511:WARNING:audio_manager_linux.cc(69)] Falling back to ALSA for audio output. PulseAudio is not available or could not be initialized.

これは私のDockerfileです。

FROM node:16.13

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium

RUN apt-get update \
    && apt-get install -yq wget curl gnupg libgconf-2-4 ca-certificates wget xvfb dbus dbus-x11 build-essential --no-install-recommends

RUN apt-get update && apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 \
    libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 \
    libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 \
    libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
    libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
    libxss1 libxtst6 ca-certificates fonts-liberation libnss3 lsb-release \
    xdg-utils wget

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 chromium fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 dbus-x11 -y --no-install-recommends && \
    rm -rf /var/lib/apt/lists/\*

RUN mkdir -p /usr/src/app
VOLUME ["/usr/src/app"]
WORKDIR /usr/src/app

COPY . /usr/src/app

RUN yarn install

RUN chmod -R 777 /usr/src/app

ENTRYPOINT [ "./entrypoint.sh" ]
EXPOSE 80

これは私のものですentrypoint.sh

#!/bin/bash

# Startup Xvfb
Xvfb -ac :99 -screen 0 1280x1024x16 > /dev/null 2>&1 &

# Export some variables
export DISPLAY=:99.0

npm run-script deploy-force && npm start && sleep 6000

これは私のPuppeteer構成です。

const puppeteerConfig = {
    args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-dev-shm-usage',
        '--disable-accelerated-2d-canvas',
        '--no-first-run',
        '--no-zygote',
        '--single-process', // <- this one doesn't works in Windows
        '--disable-gpu',
        '--headless'
    ],
    headless: true,
    devtools: false,
    timeout: 90000,
    executablePath: '/usr/bin/chromium',
    dumpio: true
};

Xvfbx11接続を実行すると、そのようなことが起こると思いましたか?

ベストアンサー1

おすすめ記事