Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running X-Windows Desktop Apps in Docker Containers on Windows 10

I want to have a Linux development environment (Java, Intellij Idea, Clojure and ClojureScript) in my Windows 10 machine (i5, 8GB, 240 GB ssd, 2&1 notebook). I can use:

  1. a Linux VM (using Hyper-V, VMware Player or Virtual Box), or
  2. a docker container running desktop apps.

I would like to try the second option. In Docker Containers on the Desktop, the author runs a Chrome browser docker using:

$ docker run -it \
--net host \ # may as well YOLO
--cpuset-cpus 0 \ # control the cpu
--memory 512mb \ # max memory it can use
-v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
-e DISPLAY=unix$DISPLAY \ # pass the display
-v $HOME/Downloads:/root/Downloads \ # optional, but nice
-v $HOME/.config/google-chrome/:/data \ # if you want to save state
--device /dev/snd \ # so we have sound
--name chrome \
jess/chrome

The Dockerfile he used can be adapted to run other desktop apps, but the command above doesn't work in Windows. I have a XWindows server running (in Windows 10), but I would like to know how to change -e DISPLAY=unix$DISPLAY and --device /dev/snd options. How can this command be changed to work?

Docker runs in Windows using a Hyper-V Linux VM. Is it going to be faster than a full Linux VM in Hyper-V (or other VM system) or is modularity the only advantage of docker in this case?

like image 686
dilvan Avatar asked Jan 04 '23 03:01

dilvan


2 Answers

The following command works (I'm using XcXsrv Xserver allowing connections from any source):

docker run -d --name firefox1 -e DISPLAY=your-machine-ip-address:0  jess/firefox

You can drop --name firefox1 if you don't want to name the docker. Movies work fine but with no sound. Does anyone can help here?

Other Xservers should work as well, just make sure you allow connections from any sources (be careful, this setup can be a security threat in open networks).

like image 190
dilvan Avatar answered Jan 14 '23 05:01

dilvan


Remember that your docker container and your host are virtually different machines. To use a GUI application from your docker container is exactly the same of running a Linux GUI application on a remote host and displaying it on your local Windows host.

When your host is a Linux machine, that's pretty easy. Your host already runs an X server. The docker container can export its X display to the host and use host's X server to run GUI applications. That's what your docker command does.

With a Windows host there is no such possibility since it does not run X, so there is no slight modification that can achieve what you want.

Your options are either running X server on Windows by using some third party tools, or using any other remote connection technology, such as VNC or RDP. But since you want a development environment, I guess you want a seamless experience and a VNC or RDP window won't work. Then you should go for running an X server on Windows.

Check out this answer for a possible way to achieve this. Also please read other answers to the question. There might be security implications of using the host X server for docker container apps. Since you are using host X server, applications are not truly sandboxed anymore.

like image 32
infiniteRefactor Avatar answered Jan 14 '23 07:01

infiniteRefactor