How can you run GUI applications 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?
How can you run GUI applications 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?
Docker with BRIDGE network. for Ubuntu 16.04 with display manager lightdm:
you can use more private permissions
OSX
Jü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:
run_docker.bash
: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.
If you want to run a GUI application headless, then read here. What you have to do is to create a virtual monitor with
xvfb
or other similar software. This is very helpful if you want to run Selenium tests for example with browsers.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
--privileged
when running the container.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:
This will create a Docker container running VNC with the password
1234
:For Docker version 1.3 or newer:
For Docker before version 1.3:
The other solutions should work, but here is a solution for
docker-compose
.To fix that error, you need to pass $DISPLAY and .X11-unix to docker, as well as grant the user who started docker access to xhost.
Within docker-compose.yml:
version: '2' services: node: build: . container_name: node environment: - DISPLAY volumes: - /tmp/.X11-unix:/tmp/.X11-unix
In terminal or script:
xhost +si:localuser:$USER
xhost +local:docker
export DISPLAY=$DISPLAY
docker-compose up