How To : Run GUI application inside a Docker container

Intro

They recently installed a Rocket.Chat server at my office which is a chat software solution. As I didn't want to install it directly on my computer and also never tried Docker I decided to put it in a container.

Configuration

Docker

Installation

root@host:~# apt install apt-transport-https ca-certificates curl software-properties-common gnupg2
root@host:~# curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
root@host:~# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
root@host:~# apt update
root@host:~# apt install docker-ce
root@host:~# systemctl status docker
root@host:~# usermod -aG docker user

Debian Image Installation

user@debian: $ docker search debian
user@debian: $ docker image pull debian
FROM debian:9

RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget gconf2 gconf-service libnotify4 libappindicator1 libxtst6 libnss3 libxss1 libasound2 sudo
RUN wget https://github.com/RocketChat/Rocket.Chat.Electron/releases/download/2.15.1/rocketchat_2.15.1_amd64.deb
RUN dpkg -i rocketchat_2.15.1_amd64.deb

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


USER user
ENV HOME /home/user
CMD rocketchat-desktop
user@debian: $ docker build -t rocket .

Launch GUI Application

user@debian: $ docker run -ti --rm -e DISPLAY  -v $HOME/.Xauthority:/home/user/.Xauthority --net=host rocket

Lauch Two Applications

Let's see what to do if we want to launch firefox and rocket.chat applications in the same container.

Applications Script

#! /bin/bash
firefox-esr&
rocketchat-desktop
chmod +x /home/user/applications.sh

Debian Image Installation

FROM debian:9

RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget gconf2 gconf-service libnotify4 libappindicator1 libxtst6 libnss3 libxss1 libasound2 sudo firefox-esr
RUN wget https://github.com/RocketChat/Rocket.Chat.Electron/releases/download/2.15.1/rocketchat_2.15.1_amd64.deb
RUN dpkg -i rocketchat_2.15.1_amd64.deb

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


USER user
ENV HOME /home/user
COPY ./applications.sh /home/user/
CMD /home/user/applications.sh
user@debian: $ docker build -t fire-rocket .
user@debian: $ docker run -ti --rm -e DISPLAY  -v $HOME/.Xauthority:/home/user/.Xauthority --net=host fire-rocket

Sources

Licence Creative Commons
This website http://shebangthedolphins.net is licensed to the public under a licence Creative Commons Attribution licence.
Contact :