/ docker

[Docker] Run GUI app in linux container on windows host

Docker has dozents of advantages and so is one of them to be able to use apps with a GUI isolated in a docker container. For example your Browser, TextEditor or something else.

Neatless to say that this will enable you to use linux / macOS software on your windows host without messing with some hacks. Also this will prevent your maschine from having leftover dependencies when removing the app because it all stays wrapped up in a docker container.

So there are various tutorials on how to share an X11-Session from a linux host with a linux container. But:

How to share the display from a windows host?

Install VcXsrv and configure it

First of all, install VcXsrv Windows X Server. We could use Xming also, but the package for windows hasn't been updated since 2013. The easiest way would be to use Chocolatey which is by the way my favorite package manager for windows!
So fire up a powershell session and run:

choco install vcxsrv

Then run Xlaunch from the start menu and follow the initial configuration steps:
VcXsrv_config_1
VcXsrv_config_2
VcXsrv_config_3-1
VcXsrv_config_4
Make sure to save to configuration file before you click finish!
Save it to one of the following locations:

  • %appdata%\Xming
  • %userprofile%\Desktop
  • %userprofile%

Create a Dockerfile

To use a simple example, create a new folder and place a Dockerfile with the following content in it:

FROM ubuntu:14.04
RUN apt-get update && apt-get install -y firefox
CMD /usr/bin/firefox

Build and run the container

For advanced docker users, here the quick commands:

docker build -t firefox .
set-variable -name DISPLAY -value YOUR-IP:0.0
docker run -ti --rm -e DISPLAY=$DISPLAY firefox

With some explaination:
Now build the new container and label it firefox:

docker build -t firefox .

Because the container has its own localhost interface, we need to use the IP-address of our network adapter.
Find out your ip address with

ipconfig

Set the environment variable (replace IP with yours):

set-variable -name DISPLAY -value 10.11.128.118:0.0

Run to the container:

docker run -ti --rm -e DISPLAY=$DISPLAY firefox

You should now see a firefox window:
VcXsrv_firefox

[Docker] Run GUI app in linux container on windows host
Share this

Subscribe to robsCode