Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you run GUI applications in a Linux Docker container?

How can you run GUI applications in a Linux 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?

like image 429
Will Avatar asked Apr 30 '13 09:04

Will


People also ask

Can you run GUI apps in a Docker container?

Follow the below steps to run a GUI application inside Docker: Step 1: Install and Start Docker and check the status and restart the service. The Systemctl commands are used to manage system services. systemctl start docker // to start the docker service.

Can I run Windows GUI in Docker?

The short answer here is no. Windows containers don't have the underlying GUI components available, so you can't run any desktop application on Windows containers.

Can Docker run desktop apps?

Desktop applications will run in Docker and will try to communicate with the X server you're running on your PC. This can take place either with a Docker engine running on your host or in a Docker engine running on a remote machine.

Does Docker container have UI?

If you want that UI application to display the user interface on your local machine while running the application inside the Docker Container, you will have to connect the display of the Docker Container with the display of your local machine.


2 Answers

You can simply install a vncserver along with Firefox :)

I pushed an image, vnc/firefox, here: docker pull creack/firefox-vnc

The image has been made with this Dockerfile:

# Firefox over VNC # # VERSION               0.1 # DOCKER-VERSION        0.2  FROM    ubuntu:12.04 # Make sure the package repository is up to date RUN     echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN     apt-get update  # Install vnc, xvfb in order to create a 'fake' display and firefox RUN     apt-get install -y x11vnc xvfb firefox RUN     mkdir ~/.vnc # Setup a password RUN     x11vnc -storepasswd 1234 ~/.vnc/passwd # Autostart firefox (might not be the best way to do it, but it does the trick) RUN     bash -c 'echo "firefox" >> /.bashrc' 

This will create a Docker container running VNC with the password 1234:

For Docker version 18 or newer:

docker run -p 5900:5900 -e HOME=/ creack/firefox-vnc x11vnc -forever -usepw -create 

For Docker version 1.3 or newer:

docker run -p 5900 -e HOME=/ creack/firefox-vnc x11vnc -forever -usepw -create 

For Docker before version 1.3:

docker run -p 5900 creack/firefox-vnc x11vnc -forever -usepw -create 
like image 197
creack Avatar answered Oct 03 '22 04:10

creack


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.

docker build -t xeyes - << __EOF__ FROM debian RUN apt-get update RUN apt-get install -qqy x11-apps ENV DISPLAY :0 CMD xeyes __EOF__ XSOCK=/tmp/.X11-unix XAUTH=/tmp/.docker.xauth xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - docker run -ti -v $XSOCK:$XSOCK -v $XAUTH:$XAUTH -e XAUTHORITY=$XAUTH xeyes 
like image 40
Jürgen Weigert Avatar answered Oct 03 '22 02:10

Jürgen Weigert