1

I am trying to run a GUI app inside docker container using X11 forwarding and am not able to get it to work even when binding Xauthority file.

# Dockerfile
FROM alpine

RUN apk --no-cache add xterm
RUN adduser --disabled-password --home /home/user --uid 1000 --gecos 'USER' user
WORKDIR /home/user
USER user

CMD /usr/bin/xterm

I have tried the following commands to run, and none have been successful:

docker run -it --rm -e DISPLAY image
docker run -it --rm -e DISPLAY -v /tmp/.X11-unix image
docker run -it --rm -e DISPLAY -e XAUTHORITY -v $XAUTHORITY image
docker run -it --rm -e DISPLAY -e XAUTHORITY -v $XAUTHORITY -v /tmp/.X11-unix image
docker run -it --rm --net=host --privileged -e DISPLAY -e XAUTHORITY -v $XAUTHORITY -v /tmp/.X11-unix image

Basically, they all produce the same error Can't open display: :0. At this point, I have run out of all options discussed at StackOverflow and other tutorials

I am not sure if the permissions on the Xauthority file is important, but when I bind, from inside the container, it has root:root permissions where the host has user:user permissions.

I have also used (Can you run GUI applications in a Docker container?) but have not had any success with the answers

Sudarshan
  • 161
  • 2
  • 11
  • Have a look at [this](https://blog.jessfraz.com/post/docker-containers-on-the-desktop/) post specifically the GUI section. The developer is|was at Docker and a proponent of showing how to run most everything under Docker. HTH! – DazWilkin Nov 18 '19 at 00:02
  • I have used those images also but I have the same issue with them. I have used the UNIX socket and display variable set to unix:0, but I still get the same error – Sudarshan Nov 18 '19 at 00:13
  • Ah, I'm outta ideas, sorry. – DazWilkin Nov 18 '19 at 00:17
  • I tried adding 755 permissions on host for XAUTHORITY file and am able to connect, but this requires --privileged tag. Do you have any suggestions which does not require --privileged – Sudarshan Nov 18 '19 at 02:21

1 Answers1

-1

Have you tried xhost + prior to running your container (so your local X server will accept connections from the container)? You'll still need to set DISPLAY etc. something like this:

docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e "DISPLAY=unix:0.0" --device /dev/dri --privileged -it --rm yourapp

Note: xhost + allows incoming X connections from anywhere, so be careful with that!

John K
  • 1
  • 1
  • Can also run `xhost -` after the docker container is finished... – John K Jan 04 '22 at 19:52
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 05 '22 at 07:13