How can you run GUI apps in a docker container?
Are there any images that set up vncserver
or something so that you can - for example - add an extra speedbump sandbox around say Firefox?
|
You can simply install a vncserver along with firefox :) I pushed an image vnc/firefox here: The image has been made with this Dockerfile:
This will create a docker container running vnc with the password For docker version 1.3 or newer:
For docker before version 1.3:
|
|||||||||||||||||||||
|
Xauthority becomes an issue with newer systems. I can either discard any protection with xhost + before running my docker containers, or I can pass in a well prepared Xauthority file. Typical Xauthority files are hostname specific. With docker, each container can have a different host name (set with docker run -h), but even setting the hostname of the container identical to the host system did not help in my case. xeyes (I like this example) simply would ignore the magic cookie and pass no credentials to the server. Hence we get an error message 'No protocol specified Cannot open display' The Xauthority file can be written in a way so that the hostname does not matter. We need to set the Authentication Family to 'FamilyWild'. I am not sure, if xauth has a proper command line for this, so here is an example that combines xauth and sed to do that. We need to change the first 16 bits of the nlist output. The value of FamilyWild is 65535 or 0xffff.
|
|||||||||||||||||||||
|
With docker data volumes it's very easy to expose xorg's unix domain socket inside the container. For example, with a Dockerfile like this:
You could do the following:
This of course is essentially the same as X-forwarding. It grants the container full access to the xserver on the host, so it's only recommended if you trust what's inside. Note: If you are concerned about security, a better solution would be to confine the app with mandatory- or role-based-access control. Docker achieves pretty good isolation, but it was designed with a different purpose in mind. Use AppArmor, SELinux, or GrSecurity, which were designed to address your concern. |
|||||||||||||||||||||
|
i just found this blog entry and want to share it here with you because i think it is the best way to do it and it is so easy. http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/ PROS: CONS: in case the link will fail some day i have put the most important part here:
build the image:
and the run command:
of course you can also do this in the run command with HINT: for audio take a look at: http://stackoverflow.com/a/28985715/2835523 |
|||||||||
|
You can also use subuser: https://github.com/timthelion/subuser This allows you to package many gui apps in docker. Firefox and emacs have been tested so far. With firefox, webGL doesn't work though. Chromium doesn't work at all. EDIT: Sound works! EDIT2: In the time since I first posted this, subuser has progressed greatly. I now have a website up subuser.org, and a new security model for connecting to X11 via XPRA bridging. |
|||||||||||||
|
Here's a lightweight solution that avoids having to install any It assumes that you connect to the host machine using In the
So that the forwarded X server port on the host is opened on all interfaces (not just The container, when run, needs access to the
That is not enough, we also have to pass the DISPLAY variable from the host, but substituting the hostname by the ip:
We can define an alias:
And test it like this:
|
|||||||||||||
|
OSXJürgen Weigert has the best answer that worked for me on Ubuntu, however on OSX, docker runs inside of VirtualBox and so the solution doesn't work without some more work. I've got it working with these additional ingredients:
I'd appreciate user comments to improve this answer for OSX, I'm not sure if socket forwarding for X is secure, but my intended use is for running the docker container locally only. Also, the script is a bit fragile in that it's not easy to get the IP address of the machine since it's on our local wireless so it's always some random IP. The BASH script I use to launch the container:
I'm able to get xeyes and matplotlib working with this approach. Windows 7+It's a bit easier on Windows 7+ with MobaXterm:
|
||||
There is another solution by lord.garbage to run GUI apps in a container without using VNC, SSH and X11 forwarding. It is mentioned here too. |
|||||
|
Sharing host display :0, as stated in some other answers, has two drawbacks:
To circumvent X security leaks and to avoid MIT-SHM issue, I have published x11docker on github. The main idea is to run a second X server with its own authentication cookies and with MIT-SHM disabled. docker containers get access to the new X server and are segregated from host display :0. There are no X dependencies inside the image as X / Xephyr is provided by host. Below an example script to run a docker image in Xephyr.
It expects some arguments, first a host window manager to run in Xephyr, second a docker image, optionally third
an image command to be executed.
To run a desktop environment in docker, use ":" instead of a host window manager.
On systems without a root password, change variable Xephyr is started using xinit. A custom xinitrc is created to create a cookie, to set keyboard layout, to run window manager, and to run xterm with xtermrc to prompt for password to run docker. Closing Xephyr window terminates docker container applications. Terminating the dockered applications closes Xephyr window. Annotations:
Examples:
x11docker_example script:
|
||||
|
If you want to run a GUI application headless, then read here. What you have to do is to create a virtual monitor with Something not mentioned anywhere is that some software actually themselves use sand-boxing with Linux containers. So for example Chrome will never run normally if you don't use the appropriate flag |
|||
|
For OpenGL rendering with the Nvidia driver, use the following image: https://github.com/thewtex/docker-opengl-nvidia For other OpenGL implementations, make sure the image has the same implementation as the host. |
|||
|
You can allow the Docker user (here: root) to access the X11 display:
|
|||
|
This is not lightweight but is a nice solution that gives docker feature parity with full desktop virtualization. Both Xfce4 or IceWM for Ubuntu and CentOS work, and the https://github.com/ConSol/docker-headless-vnc-container It runs |
||||
|
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?