0

I am struggling to run my cucumber tests from a Docker image.

Here is my setup:

  1. I use OSX with XQuartz to run an X11 session
  2. I use an Ubuntu 14 Vagrant image for development where I forward my X11 session
  3. I am trying to run a docker image with Firefox that will use my XQuartz session for display

So far, I managed to start Firefox with the following setup:

# Dockerfile
FROM ubuntu:14.04

RUN apt-get update && apt-get install -y firefox

# Replace 1000 with something appropriate ;)
RUN export uid=1000 gid=1000 && \
     mkdir -p /home/developer && \
     echo "developer:x:${uid}:${gid}:Developer,,,:/home/dev:/bin/bash" >> /etc/passwd && \
     echo "developer:x:${uid}:" >> /etc/group && \
     echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
     chmod 0440 /etc/sudoers.d/developer && \
     chown ${uid}:${gid} -R /home/developer

USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

I can start Firefox with --net=host from my Vagrant machine:

docker build -t firefox .
docker run --net=host -ti --rm -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/home/developer/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix:rw firefox:latest

But this is not ideal because I can't link other containers to my machine in the docker-compose.yml file. Ideally, I would like to run my docker machine without --net=host like this:

docker build -t firefox .
docker run -ti --rm -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/home/developer/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix:rw firefox:latest

But I get the following error:

error: XDG_RUNTIME_DIR not set in the environment.
Error: cannot open display: localhost:10.0

Please help :)

Igor Šarčević
  • 3,481
  • 1
  • 19
  • 21
  • Are you specifically trying to use X11 because you want to see the tests or are you open to something like Xvfb that runs a virtual framebuffer in container where you don't need a X11 server? I ask because I have used the official Selenium images at https://hub.docker.com/r/selenium/ to run Selenium tests in Firefox and Chrome using the Selenium Hub and it works well. – Andy Shinn Jul 03 '17 at 18:12
  • Yes, my primary reason for not using xvfb is because I want to see and debug my tests. Xvfb is great for CI. – Igor Šarčević Jul 04 '17 at 07:14

1 Answers1

1

You could simply use elgalu/docker-selenium to avoid dealing with what's already solved for you, and maintained:

docker run --rm -ti --net=host --pid=host --name=grid \
   -e SELENIUM_HUB_PORT=4444 -e TZ="US/Pacific" \
   -v /dev/shm:/dev/shm --privileged elgalu/selenium

If you need advanced features like a dashboard with video recording for example, or live preview, you can use Zalenium and start it with:

curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start -i
Leo Gallucci
  • 16,355
  • 12
  • 77
  • 110