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
x11My 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 bashI 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-2004The output is:
DISPLAY=:0
Error: Can't open display: :0
Done.and the xclock gui window is not showing. What am I missing here?
3 Answers
The problem is most likely that you installed docker with snap. According to mviereck the maintainer of x11docker
snapcauses several restictions.--hostdisplaydoes not work because it is not possible to share unix sockets from host, in this case the X unix socket in/tmp/.X11-unix
A workaround is to an Xephyr X server with x11docker. Instead of running docker run ... gui-test-ubuntu-2004, use:
x11docker --xephyr gui-test-ubuntu-2004The second alternative is to remove the snap installation of docker, see this answer, and then reinstall docker with apt-get install:
Remove docker:
sudo snap remove dockerGo to and choose your Ubuntu version, then browse to
pool/stable/and download the 3.debfiles:containerd.io_1.2.13-2_amd64.deb
docker-ce_19.03.11_3-0_ubuntu-focal_amd64.deb
docker-ce-cli_19.03.11_3-0_ubuntu-focal_amd64.deb
Install them in the following order:
sudo apt-get install ./containerd.io_1.2.13-2_amd64.deb sudo apt-get install ./docker-ce-cli_19.03.11_3-0_ubuntu-focal_amd64.deb sudo apt-get install ./docker-ce_19.03.11_3-0_ubuntu-focal_amd64.debAdd your user to the docker group to avoid having to type
sudoto rundocker:sudo addgroup --system docker sudo usermod -a -G docker $USERRestart the computer at this point to activate the new user and group settings
Test the docker installation by running :
docker run hello-world
You should now be able to run the original docker run command:
docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY \ -h $HOSTNAME -v $HOME/.Xauthority:/home/hakon/.Xauthority gui-test-ubuntu-2004 1 Type xhost + local:docker before running docker.
I was testing this but it was raising the error.standard_init_linux.go:228: exec user process caused: exec format error
My docker was installed following the instructions here:
I added the the #!/bin/bash on the first line of your entrypoint.sh and it's working for me.