Posted on

I have been using docker for a while. One thing that I encountered and thought should be interesting is to run a container with a GUI in a windows host, which give me both audio and video of the program. For this test I am using Mozilla Firefox.

This requires docker to be set up. I am running docker on WSL2. We will be using this simple dockerfile as a starting point:

FROM ubuntu:18.04

RUN  apt-get update \
    && apt-get install -y \
        firefox

CMD /usr/bin/firefox http://arnav.jain.se/

Video / Gui

What we will be doing is capturing the gui elements sent to the X Server and show them in windows.

VcXsrv Windows X Server

Installation

The easiest way to install VcXsrv is using Chocolatey.

choco install vcxsrv

Configuration

Start XLaunch for configuration:

Display Settings: Multiple Windows
Display Number: -1
Client Startup: Start no client
Extra Settings:
    Clipboard: Yes
        Primary Selection: Yes
    Native opengl: Yes
    Disable access control: Yes

Note Disable access control above should be ticked.

Save configuration as %appdata\Xming\config.xlaunch% and press finish to start VcXsrv

Contents of the file should be something like this:

<?xml version="1.0" encoding="UTF-8"?>
<XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="-1" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="True" ExtraParams="" Wgl="True" DisableAC="True" XDMCPTerminate="False"/>

Docker

In our dockerfile we will add the following:

ENV DISPLAY=host.docker.internal:0.0

The dockerfile now looks like following:

FROM ubuntu:18.04

RUN  apt-get update \
    && apt-get install -y \
        firefox

ENV DISPLAY=host.docker.internal:0.0

CMD /usr/bin/firefox http://arnav.jain.se/

We can test our progress with:

docker build -t firefox . && docker run --rm firefox

If the image is built successfully, a new firefox window should open.

Audio

For audio we will be using Pulseaudio on Windows

Pulseaudio on Windows

Installation

Download the archive available at the download site and extract the files to a folder of your choice.

Configuration

We need to change the configuration in certain files.

We start with etc\pulse\default.pa We need to add the following line, somewhere around line 62 is resonable.

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1

Next file is etc\pulse\daemon.conf where we need to uncomment exit-idle-time and set value to -1 (line 39).

exit-idle-time = -1

Running

Running is simple as starting bin\pulseaudio.exe. You should receive a firewall prompt, allow access. The command prompt will probably show a few warnings about Secure directory creation not supported on Win32. If the process does not exit, then the pulseaudio server is running.

Docker

In our dockerfile we will add the following:

ENV PULSE_SERVER=tcp:host.docker.internal:4713

We will also require installing pulseaudio in the docker container (in addition to firefox).

The dockerfile now looks like following:

FROM ubuntu:18.04

RUN  apt-get update \
    && apt-get install -y \
        pulseaudio \
        firefox

ENV DISPLAY=host.docker.internal:0.0
ENV PULSE_SERVER=tcp:host.docker.internal:4713

CMD /usr/bin/firefox http://arnav.jain.se/

We can again test our progress with:

docker build -t firefox . && docker run --rm firefox

This time when the firefox opens, let’s try navigating to Soundcloud and try playing some music.

comments powered by Disqus