Launching Google Chrome on Docker container

Objective

Launch GUI applications(Google Chrome in this case) on top of Docker container.

Content of this Blog

  • Prerequisite
  • Project Understanding
  • Output

Prerequisites

For Docker, refer the following link:

Project Understanding

Docker containers are by default CLI-based in nature and requires a physical display to run GUI applications. The way to do so involves sharing of Docker host’s display with the container.

In order to perform the above operation, two important concepts needs to be understood which are as follows:

  1. X11 or X Server
  2. DISPLAY environment variable

Let’s understand each one of them

X11 or X Server

X11 is a client/server windowing system for bitmap displays. It is implemented on most UNIX-like operating systems and has been ported to many other systems.

X Server is the program or dedicated terminal that displays the windows and handles input devices such as keyboards, mouse and touchscreens.

DISPLAY environment variable

The DISPLAY environment variable is used by all X clients to determine what X server to display on. Since any X client can connect to any X server that allows it, all X clients need to know what needs to be displayed upon startup.

The format of the DISPLAY variable is

hostname:D.S

where,

  • hostname: Name or IP of the host
  • D: Display number in case of multiple displays (usually 0)
  • S: Screen number in case of multiple screens (usually 0)

Implementation: Dockerfile

FROM centos:latest
LABEL maintainer "Satyam Singh"

RUN dnf update -y
COPY google-chrome.repo /etc/yum.repos.d/
RUN yum install google-chrome-stable -y
ENTRYPOINT ["google-chrome","--no-sandbox"]

The above Dockerfile updates the DNF/YUM repository and copies the repository required for installation of Google Chrome in yum.repos.d directory, then it installs it using yum and then sets an entrypoint for launching Google Chrome.

Docker Host : RHEL 8

Implementation: Command used for building an image

docker build -t <image_name>:<version_tag> <path_to_Dockerfile>

Implementation: Command used to run Google Chrome within the container

docker run -it -e DISPLAY=:0 -v /tmp/.X11-unix:/tmp/.X11-unix -- chrome <URL>

where,

  • -e stands for export and is used for exporting the value of environment variable DISPLAY
  • -v stands for bind mount to a volume i.e., attaching a volume

The X server folder i.e., /tmp/.X11-unix present in the host is mounted to the Docker container using -v option. The reason behind the same is to provide an X server to the container for running GUI applications.

Output

Command Used
Command Output

Thank You !!!

LinkedIn Profile :