rss logo

How To Run GUI application inside a Docker container

Docker logo

Intro

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

Configuration

  • OS : Debian 11
  • Docker : 20.10.6

Docker GUI Application

Installation

  • Install the necessary packages to add the Docker repository:
root@host:~# apt install apt-transport-https ca-certificates curl software-properties-common gnupg2
  • Import the Docker gpg key:
root@host:~# curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
  • Add Docker repository:
root@host:~# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
  • Refresh packages list:
root@host:~# apt update
  • Install Docker:
root@host:~# apt install docker-ce
  • Check Docker service status:
root@host:~# systemctl status docker
  • Permit the user to run Docker commands (then restart the current session for it to work):
root@host:~# usermod -aG docker user

Debian Image Installation

  • Search Debian images:
user@debian:~$ docker search debian
  • Download Debian images:
user@debian:~$ docker image pull debian
  • Create /home/user/Docker/rocket:
FROM debian:11 RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget gconf2 gconf-service libnotify4 libappindicator1 libxtst6 libnss3 libxss1 libasound2 sudo libsecret-1-0 xdg-utils libgbm1 RUN wget https://github.com/RocketChat/Rocket.Chat.Electron/releases/download/3.9.3/rocketchat-3.9.3-linux-amd64.deb RUN dpkg -i rocketchat-3.9.3-linux-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
  • Build rocket image from Dockerfile:
user@debian:~$ cd /home/user/Docker user@debian:~$ docker build -t rocket .

Launch GUI Application

user@debian:~$ docker run --privileged -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

  • First we create a /home/user/applications.sh file:
#! /bin/bash firefox-esr& rocketchat-desktop
  • We make it executable
user@debian:~$ chmod +x /home/user/applications.sh

Debian Image Installation

  • Then we create /home/user/Docker/fire-rocket configuration file:
FROM debian:11 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 libsecret-1-0 xdg-utils libgbm1 RUN wget https://github.com/RocketChat/Rocket.Chat.Electron/releases/download/3.9.3/rocketchat-3.9.3-linux-amd64.deb RUN dpkg -i rocketchat-3.9.3-linux-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
  • Build fire-rocket image from Dockerfile
user@debian:~$ docker build -t fire-rocket .
  • Launch GUI applications
user@debian:~$ docker run --privileged -ti --rm -e DISPLAY -v $HOME/.Xauthority:/home/user/.Xauthority --net=host fire-rocket

References

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address