Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot launch two chromium instances in single docker container #50

Open
Terrible59 opened this issue Feb 9, 2022 · 0 comments
Open

Comments

@Terrible59
Copy link

Hi! I'm having an issue with running several bots in one docker container simultaneously. The first bot starts successfully, but when I'm trying to start another bot this error pops up:

(node:4057) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
[4923:4963:0209/171529.968614:ERROR:bus.cc(396)] Failed to connect to the bus: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender="(null)" (in>
[4983:4983:0209/171530.593904:ERROR:viz_main_impl.cc(169)] Exiting GPU process due to errors during initialization


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/var/www/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:229:20)
    at Interface.<anonymous> (/var/www/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:219:68)
    at Interface.emit (events.js:326:22)
    at Interface.close (readline.js:416:8)
    at Socket.onend (readline.js:194:10)
    at Socket.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1241:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:4057) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was >
(node:4057) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code

Node v12.22.9
OS(in container): Debian 9.13
My dockerfile:

FROM node:12

RUN apt-get update \
    && apt-get install -y dbus-x11 software-properties-common wget gnupg \
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && 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 -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

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 libatk-bridge2.0-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 libappindicator1 libnss3 lsb-release xdg-utils wget x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps xvfb

RUN mkdir -p /var/www/app
WORKDIR /var/www/app

# Install app dependencies
COPY package.json .
RUN npm install
RUN npm i concurrently -g
RUN npm i nodemon -g

RUN apt install chromium -y \
    && apt-get update \
    && apt install chromium -y

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
    PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium

# Install puppeteer so it's available in the container.
RUN npm init -y &&  \
    npm i puppeteer \
    # Add user so we don't need --no-sandbox.
    # same layer as npm install to keep re-chowned files from using up several hundred MBs more space
    && groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
    && mkdir -p /home/pptruser/Downloads \
    && chown -R pptruser:pptruser /home/pptruser \
    && chown -R pptruser:pptruser ./node_modules \
    && chown -R pptruser:pptruser ./package.json \
    && chown -R pptruser:pptruser ./package-lock.json 

# Run everything after as non-privileged user.
# USER pptruser

# Bundle app source
COPY . .

ENV PATH="${PATH}:./node_modules/.bin"
ENV DISPLAY :99

CMD ["bash", "/var/www/app/entrypoint.sh"]

launcher.js :

const options = {
        headless: false,
        devtools: false,
        ignoreHTTPSErrors: true,
        args: [
            `--no-sandbox`,
            `--disable-setuid-sandbox`,
            `--ignore-certificate-errors`
        ]
};
const browser = await puppeteer.launch(options);
const browserWSEndpoint = await browser.wsEndpoint();
console.log("browserWSEndpoint----- :> ", browserWSEndpoint);
await browser.disconnect();
 return browserWSEndpoint;

index.js:

FakeBrowser.globalConfig.internalHttpServerPort = getRandomInt(17300, 17400);
let WSEndPoint = await launcher();
console.log("WSENDPOINT :", WSEndPoint);
const builder = new FakeBrowser.Builder()
            .displayUserActionLayer(true)
            .proxy({
                proxy: `http://${this.proxy.ip}:${this.proxy.port}`,
                exportIP: this.proxy.ip,
                username: this.proxy.login,
                password: this.proxy.password
            })
            .vanillaLaunchOptions({
                headless: false,
                pipe: false,
                browserWSEndpoint: WSEndPoint,
                args: [
                    "--disable-setuid-sandbox",
                    "--no-sandbox",
                ],
            })
            .userDataDir(`/${pathToApp}/data/fingerprints/${this.user.id}`);
this.browser = await builder.launch();

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant