2

So I have a weird issue with a python script I'm trying to run... this works:

docker run -it <my image> /bin/bash

<inside container> xvfb-run python myscript.py <arg>

Everything starts up, firefox launches in headless mode, it's all good.

This doesn't work:

docker run -d <my image> /bin/bash -c "xvfb-run python myscript.py <arg>"

docker top shows that the cmd is running, but nothing else happens.

Why would the behavior be different from when I'm running it the second way?

mcheshier
  • 715
  • 4
  • 13
  • 1
    What happens if you add `-t` or `-ti` to the second command? – morxa Mar 17 '16 at 00:55
  • Same thing, unfortunately. Docker top shows /bin/sh /usr/bin/xvfb-run python myscript.py and Xvfb :99. Looking at top when running it successfully, I see the exact same Xvfb information, so I don't think it's that. – mcheshier Mar 17 '16 at 16:52

1 Answers1

0

So for anyone else who runs into this problem, here's how I ended up solving it:

Don't use xvfb-run. I'm not sure why but docker gets really unhappy. You need to have Xvfb already running in the background. But you have to do it a certain way!

I wasn't able to get Docker working with Xvfb in a RUN command, but it was happy running out of a script. Create a script called start_headless_display.sh and have it look like this:

Xvfb :1 -screen 0 1600x1200x16 &
python /myscript.py <args>

In your Dockerfile, make sure the script will be part of your image and add these instructions:

ENV DISPLAY :1.0

RUN chmod a+x /start_headless_display.sh

CMD /start_headless_display.sh

Now when you run

docker run -d <your image>

Everything should work - docker top will show your script and Firefox chugging merrily away.

mcheshier
  • 715
  • 4
  • 13