Headless Chrome in Docker using Xvfb

I am trying to run Chrome headless inside a Docker container using Xvfb. However, while ps shows Chrome processes exist, it is not reaching my test website. Running the same commands outside Docker is successful.

Xvfb :0 -screen 0 1024x768x24 &
DISPLAY=:0 google-chrome http://mytestpage.com

In Docker, I get the following messages/errors:

  • Docker containers with one public IP
  • docker web server does not shut even after deletion
  • How to list docker mounted volumes from within the container
  • How to create user in mongodb with docker-compose
  • “device or resource busy” error when trying to push image with docker
  • Pushing docker image to docker hub private repository return authentication error [closed]
  • Xlib:  extension "RANDR" missing on display ":0".
    Xlib:  extension "RANDR" missing on display ":0".
    [1180:1180:1120/051319:ERROR:desktop_window_tree_host_x11.cc(882)] Not implemented reached in virtual void views::DesktopWindowTreeHostX11::InitModalType(ui::ModalType)
    [1223:1223:1120/051319:ERROR:sandbox_linux.cc(338)] InitializeSandbox() called with multiple threads in process gpu-process
    [1180:1201:1120/051319:ERROR:browser_gpu_channel_host_factory.cc(144)] Failed to create channel.
    

    While

    ps au | grep chrome
    
    * root       128  0.1  0.4 533772 69868 ?        Sl+  06:02   0:00 /opt/google/chrome/chrome http://mytestpage.com
    * root       139  0.0  0.2 342648 44016 ?        S+   06:02   0:00 /opt/google/chrome/chrome --type=zygote
    * root       140  0.0  0.0  28132  3812 ?        S+   06:02   0:00 /opt/google/chrome/nacl_helper
    * root       143  0.0  0.0 342648  8016 ?        S+   06:02   0:00 /opt/google/chrome/chrome --type=zygote
    * root       181  0.0  0.3 523452 52392 ?        Sl+  06:02   0:00 /opt/google/chrome/chrome --type=gpu-process --channel=128.0.846512492 --supports-dual-gpus=false --gpu-driver-bug-workarounds=2,45,57 -$
    * root       298  0.0  0.0  11120  1084 ?        S+   06:05   0:00 grep chrome
    

    Running the same commands outside Docker (where it works) I get messages/errors:

    Xlib:  extension "RANDR" missing on display ":1".
    Xlib:  extension "RANDR" missing on display ":1".
    [17750:17750:1119/215139:ERROR:sandbox_linux.cc(338)] InitializeSandbox() called with multiple threads in process gpu-process
    

  • Redirect python print output to graylog2
  • Why containers network throughput is low
  • 'su' command in Docker returns 'must be run from terminal'
  • Pulling from a local docker image instead
  • How to gracefully shut down a server running in docker
  • My docker was stuck by down whalesay, what should I do?
  • One Solution collect form web for “Headless Chrome in Docker using Xvfb”

    Simple problem: setting the DISPLAY environment variable for the call is not enough when running Chrome. Also have to pass a flag to disable GPU since docker doesn’t have access to it and disable sandboxing.
    I have to export display:

    export DISPLAY=:0
    Xvfb :0 -screen 0 1024x768x24 &
    google-chrome --disable-gpu --no-sandbox http://mytestpage.com
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.