Running GUI Apps inside Docker Container
IT industry is focusing on Time saving and creating such technologies that can work smartly and fast. One of such technology is Docker that is a containerization tool.
There are two types of Applications or services can be used inside a Docker Container, that are:
- Applications that run as a Background Services(like webserver).
- GUI Applications that runs in Foreground
For a GUI Application to run, we need to have a XServer which is available as part of every Linux Desktop Environment, But within a Container we don’t have any XServer, so we will
- Share the Host’s Xserver to the container OS by creating a volume,
--volume="$HOME/.Xauthority:/root/.Xauthority:rw"
- Share the DISPLAY environment variable to the Container OS
--env="DISPLAY"
- run the OS with Host’s Network driver
--net=host
Implementation
Step 1: Pull a docker image named centos:latest
Note: I am using centos, here we can use our customized docker images also.
docker pull centos:latest
Step 2: Creating a docker container with all the properties that are listed above ( Xserver, DISPLAY environment variables and Network driver).
sudo docker run -it --name uibasedos --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" centos:latest
Step 3: Installing any GUI App
Suppose we will launch firefox here, using command “yum install firefox -y”
Step 4: Using this Firefox App
Step 5: Exiting the Container OS, using “exit” command
Hence, we can run any GUI App with this same approach.
💫Keep Learning, Keep Sharing💫