I am following this example of how to run an X11 app in a docker container. I am on Ubuntu 20.04 and using X11:
$ echo $XDG_SESSION_TYPE
x11
My Dockerfile
:
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y x11-apps
ARG user=hakon
ARG home=/home/$user
RUN groupadd -g 1000 $user
RUN useradd -d $home -s /bin/bash -m $user -u 1000 -g 1000 \
&& echo $user:ubuntu | chpasswd \
&& adduser $user sudo
WORKDIR $home
USER $user
ENV HOME $home
COPY entrypoint.sh .
ENTRYPOINT ["./entrypoint.sh"]
where entrypoint.sh
is:
echo "DISPLAY=$DISPLAY"
xclock # <-- This is the X11 application I am testing with. It shows a clock in a Window
echo "Done."
exec bash
I build the image using:
$ docker build -t gui-test-ubuntu-2004 .
Then run the container with:
$ docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY \
-h $HOSTNAME -v $HOME/.Xauthority:/home/hakon/.Xauthority gui-test-ubuntu-2004
The output is:
DISPLAY=:0
Error: Can't open display: :0
Done.
and the xclock
gui window is not showing. What am I missing here?
--user 1000:1000
. I tried this command:docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY --user 1000:1000 gui-test-ubuntu-2004
. Still the same error message:Error: Can't open display: :0
– Håkon Hægland Jun 11 '20 at 08:27id -u
andid -g
(user and group identifiers). – N0rbert Jun 11 '20 at 08:28Dockerfile
in your example, I get error:Err:5 http://archive.ubuntu.com/ubuntu disco Release 404 Not Found [IP: 91.189.88.142 80]
– Håkon Hægland Jun 11 '20 at 08:33Error: Can't open display: :0
– Håkon Hægland Jun 11 '20 at 08:37echo $XDG_SESSION_TYPE
the output isx11
– Håkon Hægland Jun 11 '20 at 09:10docker
? I installed it withsnap
– Håkon Hægland Jun 11 '20 at 10:17docker.io
package from default repositories. Then added my user to the docker group. – N0rbert Jun 11 '20 at 10:40snap
might be the issue here, see this issue: "snap causes several restictions. --hostdisplay does not work because it is not possible to share unix sockets from host, in this case the X unix socket in /tmp/.X11-unix" – Håkon Hægland Jun 11 '20 at 10:47$XAUTHORITY
instead of$HOME/.Xauthority
for the volume mount host location. – Daniel Stevens Oct 29 '20 at 07:36