Run GUI app in linux docker container on windows host
Tags: docker, software, apps, gui
Published: 2018-05-22 21:22:51

---
title: Run GUI app in linux docker container on windows host
published: true
description: OS-independent usage of software with GUI via docker
tags: docker,software,apps,gui
---

#What is this about?
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.

#Why would someone even try to do that?
I use Arch Linux on my private computer at home and Windows 10 at work. I wanted to be able to use the Evolution mail client and other handy linux apps on my windows maschine.

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](https://sourceforge.net/projects/vcxsrv/). We could use Xming also, but the package for windows hasn't been updated since 2013. The easiest way would be to use [Chocolatey](https://chocolatey.org/) 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:
![Setup1](https://thepracticaldev.s3.amazonaws.com/i/g3roivsrapgy69mqkhpc.png)
![Setup2](https://thepracticaldev.s3.amazonaws.com/i/5l5fil0nongqswsc5qx5.png)
![Setup3](https://thepracticaldev.s3.amazonaws.com/i/3eh1lry7125modpdj6a2.png)
![Setup4](https://thepracticaldev.s3.amazonaws.com/i/48tl3o3pv99vbhk06188.png)
**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 the container:
```
docker run -ti --rm -e DISPLAY=$DISPLAY firefox
```

You should now see a firefox window:
![firefox docker](https://thepracticaldev.s3.amazonaws.com/i/zbbfl8ytpwmd9erj9hxh.png)

This will work most other apps.

##Persisting data
To persist data (like for evolution mail), start the container with the correct locations mounted via a docker volume.

Find out all the locations, where your app stores data you want to persist and mount them:
```
docker run -v c:/docker/evolutionmail/home/user/.local/share/evolution:/root/.local/share/evolution -v c:/docker/evolutionmail/home/user/.config/evolution:/root/.config/evolution -ti --rm -e DISPLAY=$DISPLAY evolution
```

##Example Dockerfile for evolution mail
Here is my evolution Dockerfile in case someone needs it:
```
FROM debian
# Setup enviroment variables
ENV DEBIAN_FRONTEND noninteractive

# Installing fuse filesystem is not possible in docker without elevated priviliges
# but we can fake installling it to allow packages we need to install for GNOME
RUN apt-get install libfuse2 -y && \
cd /tmp ; apt-get download fuse && \
cd /tmp ; dpkg-deb -x fuse_* . && \
cd /tmp ; dpkg-deb -e fuse_* && \
cd /tmp ; rm fuse_*.deb && \
cd /tmp ; echo -en '#!/bin/bash\nexit 0\n' > DEBIAN/postinst && \
cd /tmp ; dpkg-deb -b . /fuse.deb && \
cd /tmp ; dpkg -i /fuse.deb

# Upstart and DBus have issues inside docker.
RUN dpkg-divert --local --rename --add /sbin/initctl && ln -sf /bin/true /sbin/initctl

# Install GNOME
RUN apt-get update && apt-get install -y xorg gnome-core gnome-session-fallback
# Pull in the hack to fix keyboard shortcut bindings for GNOME 3 
ADD https://raw.githubusercontent.com/CannyComputing/Dockerfile-Ubuntu-Gnome/master/gnome-keybindings.pl /usr/local/etc/gnome-keybindings.pl
RUN chmod +x /usr/local/etc/gnome-keybindings.pl

# Add the script to fix and customise GNOME for docker
ADD https://raw.githubusercontent.com/CannyComputing/Dockerfile-Ubuntu-Gnome/master/gnome-docker-fix-and-customise.sh /usr/local/etc/gnome-docker-fix-and-customise.sh
RUN chmod +x /usr/local/etc/gnome-docker-fix-and-customise.sh

RUN apt-get update -y && apt-get install -y dbus-x11 gnome-keyring evolution evolution-data-server seahorse sudo
RUN apt-get install -y libnotify-cil-dev
CMD ["evolution"]
```

I am curious to see what you dockerized in the comments!

~Cheers