Launching GUI application in Docker container

What do you find above?

you will say RedHat 8 linux operating system. But there is something more in this picture. Actually it is default GNOME desktop environment of RedHat linux. GNOME is the open source community which is highly supported by RedHat and other supporters include AWS, Google, Digital Ocean and more.

  • GNOME Classic
  • The Wayland protocol, which uses GNOME Shell as the Wayland compositor and display server.

What is display server?

A display server is a program which is responsible for the input and output coordination of its clients, to and from the rest of the operating system, and among the hardware and the operating system. Basically, thanks to a display server, you can use your computer graphically (GUI)

Launching Firefox in container

Step 1) Dockerfile

Step 2) Build image

docker build -t IMG_NAME(eg-centosgui) .

Step 4) Allow access to X server

xhost +

Step 3) Launch container

docker run --net=host --env="DISPLAY" --name CONTAINER_NAME IMG_NAME 
The --net=host option is used to make the programs inside the Docker container look like they are running on the host itself, from the perspective of the network. It allows the container greater network access than it can normally get.
Normally you have to forward ports from the host machine into a container, but when the containers share the host's network, any network activity happens directly on the host machine - just as it would if the program was running locally on the host instead of inside a container.--env="DISPLAY" pass through the DISPLAY environment variable from the host into the container. This tells GUI programs where to send their output.





Learning Practicing Exploring