In a PS to Using Docker as a Personal Productivity Tool – Running Command Line Apps Bundled in Docker Containers, I linked to a demonstration by Jessie Frazelle on how to connect to GUI based apps running in a container via X11. This is all very well if you have an X client, but it would be neater if we could find a way of treating the docker container as a virtual desktop container, and then accessing the app running inside it via the desktop presented through a browser.
Digging around, Guacamole looks like it provides a handy package for exposing a Linux desktop via a browser based user interface [video demo].
Very nice… Which got me wondering: can we run guacamole inside a container, alongside an X.11 producing app, to expose that app?
Via the Dockerfile referenced in Digikam on Mac OS/X or how to use docker to run a graphical app on Mac OS/X I tracked down linuxserver/dockergui, a Docker image that “makes it possible to use any X application on a headless server through a modern web browser such as chrome”.
Exciting:-) [UPDATE: note that that image uses an old version of the guacamole packages; I tried updating to the latest versions of the packages but it doesn’t just work so I rolled back. Support for Docker was introduced after the version used in the linuxserver/dockergui, but I don’t fully understand what that support does! Ideally, it’d be nice to run a guacamole container and then use docker-compose to link in the applications you want to expose to it? Is that possible? Anyone got an example of how to do it?]
So I gave it a go with Audacity. The files I used are contained in this gist that should also be embedded at the bottom of this post.
(Because the original linuxserver/dockergui was quite old, I downloaded their source files and built a current one of my own to seed my Audacity container.)
Building the Audacity container with:
docker build -t psychemedia/audacitygui .
and then running it with:
docker run -d -p 8080:8080 -p 3389:3389 -e "TZ=Europe/London" --name AudacityGui psychemedia/audacitygui
this is what pops up in the browser:
If we click through on the app, we’re presented with a launcher:
Select the app, and Hey, Presto!, Audacity appears…
It seems to work, too… Create a chirp, and then analyse it:
We seem to be able to load and save files in the nobody directory:
I tried exposing the /nobody folder by adding VOLUME /nobody to the Dockerfile and running a -v "${PWD}/files":/nobody switch, but it seemed to break things which is presumably a permissions thing? There are various user roles settings in the linuxserver/dockergui build files, so making poking around with those would fix things? Otherwise, we might have to see the container directly with any files we want in it?:-(
UPDATE: adding RUN mkdir -p /audacityfiles && adduser nobody root to the Dockerfile along with ./VOLUME /audacityfiles and then adding -v "${PWD}/files":/audacityfiles when I create the container allows me to share files in to the container, but I can’t seem to save to the folder? Nor do variations on the theme, such as s creating a subfolder in the nobody folder and giving the same ownership and permissions as the nobody folder. I can save into the nobody folder though. (Just not share it?)
WORKAROUND: in Kitematic, the Exec button on the container view toolbar takes you into the container shell. From there, you can copy files into the shared direcory. For example: cp /nobody/test.aup /nobody/share/test.aup Moving the share to a folder outside /nobody, eg to /audacityfiles means we can simply compy everything from /nobody to /audacityfiles.
Another niggle is with the sound – one of the reasons I tried the Audacity app… (If we can have the visual of the desktop, we want to try to push for sound too, right?!)
Unfortunately, when I tried to play the audio file I’d created, it wasn’t having any of it:
Looking at the log file of the container launch in Kitematic, it seems that ALSA (the Advanced Linux Sound Architecture project) wasn’t happy?
I suspect trying to fix this is a bit beyond my ken, as too are the sorting out the shared folder permissions, I suspect… (I don’t really do sysadmin – which is why I like the idea of ready-to-run application containers).
UPDATE 2: using a different build of the image – hurricane/dockergui:x11rdp1.3, from the linuxserver/dockergui x11rdp1.3 branch, audio does work, though at times it seemed to struggle a bit. I still can’t save files to shared folder though:-(
UPDATE 3: I pushed an image as psychemedia/audacity2. It works from the command line as:
docker run -d -p 8080:8080 -p 3389:3389 -e "TZ=Europe/London" --name AudacityGui -v "${PWD}":/nobody/share psychemedia/audacity2
Anyway – half-way there. If nothing else, we could create and analyse audio files visually in the browser using Audacity, even if we can’t get hold of those audio files or play them!
I’d hope there was a simple permissions fix to get the file sharing to work (anyone? anyone?! ;-) but I suspect the audio bit might be a little bit harder? But if you know of a fix, please let me know:-)
PS I just tried launching psychemedia/audacity2 public Dockerhub image via Docker Cloud, and it seemed to work…
Attempt to expose Audacity in a web browser using a docker container enhanced with guacamole
...
To build the container, run something like:
docker build -t psychemedia/audacitygui .
docker run -d -p 8080:8080 -p 3389:3389 -e "TZ=Europe/London" --name AudacityGui psychemedia/audacitygui
#via https://github.com/linuxserver/dockergui | |
# Builds a docker gui image | |
#FROM hurricane/dockergui:xvnc | |
FROM hurricane/dockergui:x11rdp1.3 | |
#Use an updated build | |
#FROM psychemedia/dockergui | |
######################################### | |
## ENVIRONMENTAL CONFIG ## | |
######################################### | |
# Set environment variables | |
# User/Group Id gui app will be executed as default are 99 and 100 | |
ENV USER_ID=99 | |
ENV GROUP_ID=100 | |
# Gui App Name default is "GUI_APPLICATION" | |
ENV APP_NAME="Audacity" | |
# Default resolution, change if you like | |
ENV WIDTH=1280 | |
ENV HEIGHT=720 | |
# Use baseimage-docker's init system | |
CMD ["/sbin/my_init"] | |
######################################### | |
## REPOSITORIES AND DEPENDENCIES ## | |
######################################### | |
#echo 'deb http://archive.ubuntu.com/ubuntu trusty main universe restricted' > #/etc/apt/sources.list | |
#echo 'deb http://archive.ubuntu.com/ubuntu trusty-updates main universe restricted' >> #/etc/apt/sources.list | |
# Install packages needed for app | |
######################################### | |
## GUI APP INSTALL ## | |
######################################### | |
# Install steps for X app | |
RUN apt-get update && apt-get install -y \ | |
audacity | |
# Copy X app start script to right location | |
COPY startapp.sh /startapp.sh | |
######################################### | |
## EXPORTS AND VOLUMES ## | |
######################################### | |
# Place whater volumes and ports you want exposed here: | |
#Trying to expose /nobody and running with -v "${PWD}/files":/nobody doesn't seem to work? | |
RUN mkdir -p /share | |
VOLUME /share | |
EXPOSE 3389 8080 |
audacity |
I had never thought that we can treat the docker container as a virtual desktop container, and then accessing the app running inside it via the desktop presented through a browser. Very interesting and promising idea that has versatile uses.