Xvfb & Docker - cannot open display
Asked Answered
F

1

20

I need to run XVFB and docker with firefox but can't get them to work together

Here is my Dockerfile :

FROM abevoelker/ruby:latest # based on ubuntu
ENV TERM linux
RUN apt-get update && apt-get install -y .....

ENV DISPLAY :99

# Install Xvfb init script
ADD xvfb_init /etc/init.d/xvfb # default xvfb init.d
RUN chmod a+x /etc/init.d/xvfb

CMD ["firefox"]

The error message I get from Firefox is

 Error: cannot open display: :99
Firecrest answered 22/8, 2015 at 0:22 Comment(4)
what about CMD["xvfb_run firefox"]Michelinemichell
Hi Michael, thanks for your help ! The problem is that the real idea behind this is to launch selenium webdriver with firefox, in a ruby program, therefore I can't use xvfb_runFirecrest
I use xvfb_run exactly for that - xvfb_run bundle exec cucumber --profile jenkinsMichelinemichell
are you running in MacOS ?Tineid
F
22

I solved this by writing a startup script which will:

  1. start xvfb
  2. start firefox

Executing the script via CMD allows the proper sequence of commands to run on container startup.

Dockerfile

...
ENV DISPLAY :99

ADD run.sh /run.sh
RUN chmod a+x /run.sh

CMD /run.sh

run.sh

Xvfb :99 -screen 0 640x480x8 -nolisten tcp &
firefox
Firecrest answered 14/9, 2015 at 15:35 Comment(4)
why is putting it into its own script any different from your original Dockerfile ?Weiner
Docker has no service manager built-in, so the Xvfb startup script didn't have any effect in the initial example. By moving it to a script, which is executed when the container starts (CMD), Xvfb is correctly launched in the container.Futilitarian
@Futilitarian could you elaborate more on that? Why is the script lunched correctly since there isn't still a service manager?Luik
if you are getting _XSERVTransmkdir: ERROR: euid != 0,directory /tmp/.X11-unix will not be created. error or warning pass -nolisten unix to the command. Xvfb :99 -screen 0 640x480x8 -nolisten tcp -nolisten unixMucoid

© 2022 - 2024 — McMap. All rights reserved.