-1

There is no obvious way to get graphical applications working in docker in Linux systems (for the novice like myself...)

I have been able to get something working owing to [this video][1] and further tweaking. However, the solution currently binds a graphics supporting docker image to a particular host because it integrates the XWindow authentication code into the image.

For clarity and to assist those who may have had difficulty getting to this point like I did, here is how to get graphics working in docker...

First, you must obtain the XWindow Sever authentication from your host. You can do so by performing the following which generates one or more lines of authentication information. Only one line is needed and it seems that the line with the actual host computer name works while, surprisingly enough, the one with the generic 'localhost.localdomain/unix:0' does not...anyway...

xauth list

The resulting lines should be of the form...

<hostname>/unix:0  MIT-MAGIC-COOKIE-1  hex-code-of-some-sort
localhost.localdomain/unix:0  MIT-MAGIC-COOKIE-1  hex-code-of-some-sort

Construct a Dockerfile as shown below and copy/past one of the lines from the output of the above command replacing all of <authentication code here> with it. Incidentally, putting the authentication code in the image binds it to this host which is the problem I am seeking to avoid.

FROM some-base-image

RUN apt-get update
RUN apt-get install -y apt-utils xauth libgl1-mesa-glx
RUN xauth add <authentication code here>

#to load and launch firefox...
RUN apt-get install -y firefox
CMD firefox

Build the a docker image from the docker file as follows, note the period on the end, it is important. (The period represents the current folder as being the default resource context, I do not know why the current folder was not simply presumed to be the default resource context.)

docker builder -t my-graphical-docker .

Create a container from the constructed image, my-graphical-image, with graphical support as follows. (Yes, the image can support graphics but the container will only expose it if you do the following complicated thing.)

docker run -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --net=host my-graphical-docker

The question is, how can we construct a container that by passes putting XWindow authentication code inside the docker image and allows for the passing of the XWindow authentication code as a parameter to the docker run command and, further, allow the registration to occur in docker's CMD.

The following does not work...but is a mock of what I am hoping for

If Dockerfile is...

...
..
CMD bash -c "xauth add $XAUTH && firefox"

then docker run command would be...

docker run -it XAUTH="$(xauth list|head -n 1)" -e DISPLAY --net=host -v /tmp/.X11-unix:/tmp/.X11-unix my-graphical-docker

One of the problem is, CMD does not allow variable expansion....

[1]: https://www.youtubecat .com/watch?v=RDg6TRwiPtg

George
  • 2,451
  • 27
  • 37

1 Answers1

1

Given the following Dockerfile containing FireFox web browser:

FROM ubuntu

RUN apt-get update \
 && apt-get install -y \
      apt-utils xauth libgl1-mesa-glx \
      firefox

ENTRYPOINT firefox

The web browser can be launched from Linux (Linux Mint 0.18) as follows:

sudo /usr/bin/docker run -it --rm \
   -u `id -u` \
   -e DISPLAY \
   -v /tmp/.X11-unix:/tmp/.X11-unix \
   gui

Thanks to BMitch

George
  • 2,451
  • 27
  • 37