Running GUI apps with container

I spent some time trying running GUI apps with container, it's working. But I want to add more details, to make it available for actual daily use.

scripts

Dockerfile to create the docker image:

# sudo docker build -f Dockerfile -t recolic/firefox-x .
FROM archlinux:base

RUN pacman -Sy firefox sudo --noconfirm

# Replace 1000 with your user / group id
RUN export uid=1000 gid=1000 && 
    mkdir -p /home/developer && 
    echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && 
    echo "developer:x:${uid}:" >> /etc/group && 
    echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && 
    chmod 0440 /etc/sudoers.d/developer && 
    chown ${uid}:${gid} -R /home/developer

USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

You need to run firefox from desktop entry every day. Use this startup command in firefox.desktop:

sudo docker run -d --name firefox-instance -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix recolic/firefox-x || sudo docker start firefox-instance

If you have authentication issue

Read the comments in original post http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/. I'm also archiving them, in case the original server going down:

 easeway • 7 years ago

It doesn't work with latest docker running on ubuntu 14.04. There's a few things missing: --net=host and .Xauthority file.

For "--net=host", by default, docker creates a separate network namespace inside the container which can't access host network stack including unix sockets. Using "--net=host" will not contain network stack, the program inside the container shares the same network stack as the host.

".Xauthority" file is required if your current X11 session requires a valid user. Otherwise X11 client fails to connect to X server.

Here's my command line:
docker run -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/home/developer/.Xauthority --net=host firefox

    Ryne Everett easeway • 7 years ago

    Thanks for the update. Since "--net=host" includes unix sockets, it seems that mounting the X11 socket manually is unnecessary. The following works for me:

    docker run -e DISPLAY -v $HOME/.Xauthority:/home/developer/.Xauthority --net=host firefox
    Ryan Kennedy easeway • 7 years ago

    Thanks! Your fix works on latest Docker on Arch as well.
    Lieven de Cock easeway • 3 years ago

    not all linux distros still use the .Xauthority in home (and as such it does not work), on more modern you can find the location by inspecting $XAUTHORITY, so it is better to write the option as :

    --volume=$XAUTHORITY:/home/developer/.Xauthority
    ses_vinyes easeway • 4 years ago

    Thanks a lot! --net=host was key to solve my problem! I thought it had only to do with network settings (as you are trying to run firefox and I was trying to launch other GUI app that doesn't need network connection) but it actually got the GUI going!
    John easeway • 6 years ago
    Ubuntu 14.04: .Xauthority doesn't appear to be needed for me. I have the uid / gid mapped correctly and `sudo xhost -`. Works fine with the user creation / configuration steps above then just mapping the X11 volume & setting display.