How to run google chrome headless in docker?

前端 未结 6 1587
栀梦
栀梦 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 08:58

    I don't have the answer but I know a container which successfully launch a headless Chrome in Docker. The selenium one:

    Selenium Chrome Node

    I use it for automated testing of my webapp in Chrome

    Hope it helps

    0 讨论(0)
  • 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
    0 讨论(0)
  • 2020-12-13 09:03

    This article is exactly what I needed to run Karma tests with Headless Chrome inside docker:

    https://hackernoon.com/running-karma-tests-with-headless-chrome-inside-docker-ae4aceb06ed3

    Basically, the solution is to run Headless Chrome with the --no-sandbox flag.

    0 讨论(0)
  • 2020-12-13 09:06

    We built a Docker image with Chrome and Chromedriver that runs Chrome in headless mode for automated tests. We're using this as a drop-in replacement for PhantomJS in our docker-compose.yml setups. The image is based on Alpine Linux and doesn't need or include Selenium so it's pretty small.

    Source: https://github.com/retreatguru/headless-chromedriver

    Docker Hub: https://hub.docker.com/r/retreatguru/headless-chromedriver

    0 讨论(0)
  • 2020-12-13 09:17

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

    0 讨论(0)
  • 2020-12-13 09:20

    I extend default Dockerfile Selenium Chrome Node by following

    FROM selenium/standalone-chrome-debug:latest
    MAINTAINER Serge Arbuzov <Serge.Arbuzov@advantechwireless.com>
    
    USER root
    
    ### jenkins set up ###
    RUN apt-get update && apt-get install -y openssh-server sudo
    RUN mkdir /var/run/sshd
    RUN adduser jenkins
    RUN echo jenkins:jenkins | chpasswd
    RUN echo "jenkins ALL=(ALL) NOPASSWD:ALL">>/etc/sudoers
    
    USER root
    RUN echo export DISPLAY=":1.5" >> /etc/environment
    ADD run.sh /run.sh
    RUN chmod +x /run.sh
    
    EXPOSE 22
    
    CMD ["/run.sh"]
    

    And my run.sh is

    #!/bin/bash
    
    Xvfb :1 -screen 5 1024x768x8 &
    /usr/sbin/sshd -D
    

    So i can use default image as Jenkins node

    0 讨论(0)
提交回复
热议问题