Execute graphical applications from Docker

Hello Clear Linux users.
I’m running clear linux and I am unable to start a simple docker graphical application (xclock) like

https://hub.docker.com/r/sshipway/xclock/

Neither GNOME on Wayland nor GNOME on X work, the command I use is

giacomo@woody ~ $ echo $DISPLAY 
:0

xhost +

docker run --rm -it  -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix    sshipway/xclock

I get:
Error: Can't open display: :0

So, my question is: how to run graphical applications within docker?

I remember I’ve recently managed to accomplish this in another linux distribution, but now I think I am missing something.

Thanks

You might need --privileged on the docker run.

Thanks znmeb, unfortunately it did not help.

giacomo@woody ~ $ docker run --rm --interactive  --privileged --env="DISPLAY" --env="QT_X11_NO_MITSHM=1"  --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw"    sshipway/xclock 
Error: Can't open display: :0

Thanks for any other advice
G

@Giacomo_S I tried the image and was able to get it to work with this command:

xhost +
docker run --rm --interactive --env=DISPLAY=$DISPLAY --env=QT_X11_NO_MITSHM=1 --volume=/tmp/.X11-unix:/tmp/.X11-unix:rw sshipway/xclock

Also, be careful copy+pasting commands that contain quotation marks from the Internet. Sometimes the formatting can inadvertently change it from a straight quote character to a curly quote character.

Thanks @puneetse, this does not work for me.
I must be missing something…
See the attached screenshot.
Let me know if you need more detailed information about my Clear Linux installation.
Giacomo.dockerX

hi @Giacomo_S, do you see any difference on GNOME on X instead of Wayland or is the error the same? I am running Clear Linux version 29860 on an Intel NUC, and was able to launch the clock with your original command:
xhost +
docker run --rm -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix sshipway/xclock

But I’m running on X not Xwayland. Can you take a look at this StackExchange issue and see if it applies?

Dear @bdeandocker_Xorg

Unfortunately, the result is exactly the same.

I take the opportunity to ask whether docker is the right tool for graphical applications or if there’s something more appropriate.
Thanks for helping solve this issue.
G.

Hello again Dear Clear Linux users and developers.
So, as to my topic, do you think docker is the appropriate tool to distribute graphical applications?
Is there something more tailored to this purpose?
I still haven’t solved the issue. If I am using docker out of its capabilities, I’ll have to find another solution, otherwise I will have to try another Linux distro to see if that configuration allows me to run graphical UIs from docker.
Thanks.

Can you check the output of sudo swupd bundle-list for containers-virt or cloud-native-basic? I’m wondering if your docker runtime is being defaulted to kata, which happens when those bundles are installed. Kata isolates containers inside lightweight VMs. If it is, you can try running the container with the --runtime=runc parameter to use the regular Docker runtime.

As to whether Docker is a good tool for distributing your graphical application, I think it depends a lot on your application and its requirements.

1 Like

Thanks @puneetse.

This is the (unsuccessful) result.

Giacomo

giacomo@woody ~/Downloads $
giacomo@woody ~/Downloads $ docker ps -a
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS                      PORTS               NAMES
c1abd6038d2c        cpascual/taurus-test:debian-stretch   "/usr/bin/supervisord"   2 weeks ago         Exited (0) 15 seconds ago                       taurus-stretch
giacomo@woody ~/Downloads $
giacomo@woody ~/Downloads $ xhost +
access control disabled, clients can connect from any host
giacomo@woody ~/Downloads $ docker run --rm -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix sshipway/xclock --runtime=runc
Error: Can't open display: :0
giacomo@woody ~/Downloads $ 
giacomo@woody ~/Downloads $
giacomo@woody ~/Downloads $ sudo swupd bundle-list |grep containers
containers-basic
containers-virt
giacomo@woody ~/Downloads $ sudo swupd bundle-list |grep cloud
giacomo@woody ~/Downloads $ 

Best regards

Giacomo

Thanks for sharing that output. It is helpful to know that you have containers-virt installed, which installs kata as the default runtime as I suspected.

Try adding the --runtime=runc earlier in the docker run command. I think it doesn’t get comprehended if it’s added after the docker image name. This command worked for me with containers-virt installed for example:

xhost +
docker run --rm --runtime=runc --interactive --env=DISPLAY=$DISPLAY --env=QT_X11_NO_MITSHM=1 --volume=/tmp/.X11-unix:/tmp/.X11-unix:rw sshipway/xclock

And/or, you can remove the containers-virt bundle to avoid the issue (sudo swupd bundle-remove containers-virt && sudo systemctl daemon-reload && sudo systemctl restart docker)

Fingers cross that it works for you this time :slight_smile:

1 Like

Thanks @puneetse! Your last suggestion did the trick!
Now one last thing to complete my question. In a previous message I asked whether docker is a good way to distribute a graphical application or not.

Actually, what I am distributing is an entire software framework to develop graphical applications for a control system. The docker image contains several layers of libraries (base control system libraries plus a multi threaded interface to the library plus qt control widgets plus Qt designer plugins and a bunch of graphical applications) and its sole purpose is to give the possibility to try the whole thing without installing all dependencies and environment.

Now that I’ve described what I use docker for, I think you can suggest me whether I am using docker properly or not.

I’ve removed the containers-virt bundle as well and now it is possible to run the xclock app without --runtime=runc (by the way, I’ve noticed there’s no trace of the --runtime option in `man docker run’ )

But why was the option necessary? Or, why was it necessary to remove containers-virt?

As you said, containers-virt run docker images in a more lightweight virtual machine. Doesn’t it provide accesso to X? Will it in the future? how much lighter is it compared to docker itself?

Thanks for solving my issue and for any forthcoming suggestion

Giacomo,

Elettra Synchrotron Radiation Facility

Trieste, Italy

containers-virt adds the kata container runtime and Clear Linux sets it as the default for docker. You can learn more about kata here: https://katacontainers.io . The VM isolation kata provides abstracts the host resources, like display, from the container.

@eadams pointed out there is an example and discussion of how to use a GUI app with kata here: https://github.com/kata-containers/runtime/issues/586#issuecomment-494598337

I still think it’s something you’ll have to evaluate yourself and consider the environments your audience will be using. I’ve certainly seen things like IDEs and Web browsers packaged as images on Docker Hub.

1 Like

Thanks @puneetse.
That’s interesting.

Have a nice day.

Giacomo