How to run google chrome headless in docker?

前端 未结 6 1593
栀梦
栀梦 2020-12-13 08:35

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

6条回答
  •  佛祖请我去吃肉
    2020-12-13 09:01

    Using this image alpeware/chrome-headless-trunk worked for me in ubuntu! The command used in that container to launch headless chrome is this:

    /usr/bin/google-chrome-unstable \
    --disable-gpu --headless --no-sandbox \
    --remote-debugging-address=0.0.0.0 \
    --remote-debugging-port=9222 --user-data-dir=/data
    

    here's a short video of the container in action

    I launched the container in Ubuntu with this command:

     docker run -it --rm -p=0.0.0.0:9222:9222 \ 
     --name=chrome-headless \
     -v /tmp/chromedata/:/data alpeware/chrome-headless-trunk
    

    then used Chrome to connect to the debug port at localhost:9222

    With some modifications you could probably get this running in Jenkins!

    Sources

    • https://hub.docker.com/r/alpeware/chrome-headless-trunk/
    • https://github.com/alpeware/chrome-headless-trunk

提交回复
热议问题