I'm having difficulty opening a GUI from within a Docker container. As a test version of doing this, I've created the following Dockerfile:
FROM centos:7
RUN yum -y update
RUN yum -y install firefox
RUN yum -y install libcanberra-gtk-module
RUN yum -y install libcanberra-gtk3-module
RUN yum -y install gedit
CMD bash
I then used it to build an image in a straight-forward way:
(base) me@machine:~/firefox-test$ docker build -t firefox-test .
I was under the impression that in order to get the resulting container to work, I should use a Docker run command that would pass the correct value for the environmental variable DISPLAY and forward the X sockets to the resulting container:
docker run --rm -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix <image name>
However, even after disabling access control to I am not able to open Firefox from within the container:
(base) me@machine:~/firefox-test$ xhost +
access control disabled, clients can connect from any host
(base) me@machine:~/firefox-test$ docker run --rm -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox-test
[root@fe740bde3923 /]# firefox
Error: cannot open display: :1
When I look at the contents of the mounted director, I see this:
[root@fe740bde3923 /]# ls -al /tmp/.X11-unix/
total 8
drwxr-xr-x 2 root root 4096 Jan 15 01:38 .
drwxrwxrwt 1 root root 4096 Jan 15 03:33 ..
which does not display the sockets included in the original directory (i.e. the one that my container should have mounted)
(base) me@machine:~/firefox-test$ ls -al /tmp/.X11-unix/
total 28
drwxrwxrwt 2 root root 4096 Dec 10 23:17 .
drwxrwxrwt 37 root root 20480 Jan 14 23:39 ..
srwxrwxrwx 1 root root 0 Dec 10 23:17 X0
srwxrwxrwx 1 root root 0 Dec 10 23:17 X1
Although, the Docker container's value of 1 for DISPLAY is correct:
(base) me@machine:~/firefox-test$ echo $DISPLAY
:1
Is my problem that I haven't managed to give my container access to the sockets? If so, how do I fix this? If not, what am I doing wrong?