Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run google chrome headless in docker?

My problem is how to run google chrome in docker container for e2e testing. I create a Dockerfile from official Jenkins image, but when try to run google chrome, it crashes and show the error:

Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted Trace/breakpoint trap (core dumped) 

The Jenkins docker image uses Debian jessie.

I can run google chrome with --headless flag and the X server is not needed.

This is my docker file:

  • https://github.com/ripper2hl/jenkinswithchrome

Jenkins official image:

  • https://github.com/jenkinsci/docker

The repo a person runs google chrome with GUI from docker:

  • https://github.com/jessfraz/dockerfiles/blob/master/chrome/stable/Dockerfile

My first approach is to use xvbf, but the process is more simple when used --headless flag.

  • https://gist.github.com/addyosmani/5336747

I can run chrome in Ubuntu server with the same commands for installation, but in docker it fails.

After other intents, I used --no-sandbox flag, but docker images shows the next error.

[0427/180929.595479:WARNING:audio_manager.cc(295)] Multiple instances of AudioManager detected [0427/180929.595537:WARNING:audio_manager.cc(254)] Multiple instances of AudioManager detected libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted 

Actually I ran this command:

google-chrome-stable --headless --disable-gpu --no-sandbox http://www.google.com

like image 852
Israel Perales Avatar asked Apr 27 '17 18:04

Israel Perales


People also ask

How do you run a puppeteer and headless Chrome in a docker container?

Using Puppeteer in Dockerconst puppeteer = require("puppeteer"); const browser = await puppeteer. launch({ headless: true, args: [ "--disable-gpu", "--disable-dev-shm-usage", "--disable-setuid-sandbox", "--no-sandbox", ] }); const page = await browser. newPage(); await page.

How do I run ChromeDriver in headless mode?

Post version 59, Chrome supports headless execution. ChromeOptions class is utilized to modify the default characteristics of the browser. The addArguments method of the ChromeOptions class is used for headless execution and headless is passed as a parameter to that method.

How do I run Chrome headless in Linux?

You can run Google Chrome in headless mode simply by setting the headless property of the chromeOptions object to True. Or, you can use the add_argument() method of the chromeOptions object to add the –headless command-line argument to run Google Chrome in headless mode using the Selenium Chrome web driver.

Can you run Chrome in a container?

Without the display variable we can't run GUI apps inside a container. Now chrome runs inside the container, as we had mentioned DISPLAY variable while launching this container!


1 Answers

Just launch chrome with --no-sandbox that s resolves the problem

like image 153
Boikot Avatar answered Oct 20 '22 04:10

Boikot