1

I'm trying to run Firefox in a Debian docker image but can't connect to the X11 server.

I'm using the method described here, but changed the base image to the latest Debian. I also changed the user creation method.

Dockerfile

FROM debian:latest                                                                 
RUN apt-get update && apt-get install -y firefox-esr
RUN useradd --shell /bin/bash --create-home developer && \
    usermod -aG sudo developer
  
USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

Building the container

docker build -t firefox .

Command to start the container

docker run -ti --rm \
   -e DISPLAY=$DISPLAY \
   -v /tmp/.X11-unix:/tmp/.X11-unix \
   firefox

ERROR

Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0

Operating system

OpenSUSE Leap 15.2

Context

I'm doing the above to understand how to run a GUI app via docker. The aim is to run the latest version of FreeCAD (v19), which is currently broken on OpenSUSE.

pandita
  • 4,739
  • 6
  • 29
  • 51
  • 1
    If you want to run X11 applications in `docker` / want to learn about the inner workings I can recommend having a look into [`x11docker`](https://github.com/mviereck/x11docker)! – acran Dec 30 '20 at 15:21
  • @acran Looks great! Will go through this one for sure – pandita Dec 30 '20 at 18:51

1 Answers1

3
docker run --rm \
--net=host \
--env="DISPLAY" \
--volume="$HOME/.Xauthority:/home/developer/.Xauthority:rw" \
firefox

This should work with your Dockerfile!

Couple of points

  • .Xauthority file also needs to be shared as it holds the cookies and auth sessions for the X server. Hence it has to be read/write too.
  • If you dont want to do --net=host then you can listen on a TCP port bound to unix socket and forward that to the container.
Akshay Shah
  • 704
  • 4
  • 11
  • Thanks heaps, it does work indeed! Where can I read more about how this works? I know very little about .Xauthority, etc. Do you have any good resources? – pandita Dec 30 '20 at 18:50