Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a NOT headless chrome on a docker container

Running chrome on docker machines is only possible when chrome is headless. Unfortunately, headless chrome can't ignore certificate errors which prevents my tests from running.

I'm trying to run an already working NodeJS e2e test environment on a docker container. Most of the tests pass but when a site requires a certificate it can't be accessed. On none headless chrome I can simply ignore the certification error. The base docker image installed on the container is Node:8

{
 browserName: 'chrome',
 chromeOptions: {
   binary: puppeteer.executablePath(),
   args: [
     '--lang=en-US','--headless','--no-sandbox','--ignore-certificate-errors'
   ]
}

The expected result is to either run chrome with gui on a docker container or somehow ignore the server certificate errors in headless chrome.

like image 563
Bishok Avatar asked Dec 27 '18 09:12

Bishok


2 Answers

Use Xvfb. This will allow you to use Chrome with GUI.

The idea is simple: you use virtual desktop. Configuring multiple desktops / displays on a standalone VM took some efforts. With Docker it is simple.

Some examples:

http://www.mattzeunert.com/2018/07/21/running-headful-chrome-on-ubuntu-server.html

https://medium.com/dot-debug/running-chrome-in-a-docker-container-a55e7f4da4a8

like image 55
mentallurg Avatar answered Oct 24 '22 08:10

mentallurg


Another way (described here by Nils De Moor) is to let the docker container connect to your local machine's X server.

Say your ip address is 192.168.0.2.

You can set up a tunnel to you X display on i.e. port 6010, (which corresponds to display 192.168.0.2:10) with socat. For security, the range argument asks socat to only accept connections from your machine's IP address.

socat TCP-LISTEN:6010,reuseaddr,fork,range=192.168.0.2/32 UNIX-CLIENT:\"$DISPLAY\" &

Now you can set the DISPLAY variable inside the docker container with -e when you start it.

docker run -e DISPLAY=192.168.0.2:10 gns3/xeyes

In the case of chrome there are some more complications, described in the linked post, because chrome requires some more privileges (i.e. add --privileged )

like image 39
larsr Avatar answered Oct 24 '22 07:10

larsr