Running X Client Using Virtual X Server Xvfb

Introduction

Sometimes, when I run some programs, which normally run on a local computer with a graphical display, in Docker container, they would somehow fail. Sometimes, I need to run many simulations that have GUIs simultaneously, and I don’t want to see those GUIs at all. Is there any virtual display which allows me to put the graphics into? The answer is yes and we could use X virtual framebuffer, Xvfb.

In this blog post, I would like to take you to glimpse the X server-client architecture for displaying graphics, and discuss how to use Xvfb.

X Server-Client

In computing, the X Window System, commonly known as X11 or X, is a network-transparent windowing system for bitmap displays. X uses a client-server model. An X server program runs on a computer with a graphical display and communicates with various client programs.

X Server-Client Architecture

Any application that requires GUI and interacts with X server program is called X client. X client typically includes applications such as OS GUI, web browser, most of the games, and so on. Without X server, some of those programs would fail to run.

X server requires a graphical display. Without a graphical display, X server will not start and thus all the X clients that must run on a X server would fail.

In some scenarios where X server is not started or there is no display, we would still like to run X clients, we should use a virtual X server to host the X clients. Instead of outputting signals to screen, the virtual X server outputs signals to memory. This will be very useful for running programs, especially those whose display graphics are not important, in Docker container or on remote servers. For example, if you would like to watch a live streaming on a remote server without graphical display and take some snapshots routinely every 5 minutes, virtual X server will be very helpful. In fact, some libraries, such as Matplotlib (without using agg backend) and TikZ requires to be hosted on X server. If there is no display, say in a Docker container, running the programs that use those libraries will fail.

X Virtual Framebuffer (Xvfb)

Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. In contrast to other display servers, Xvfb performs all graphical operations in virtual memory without showing any screen output.

To install Xvfb, please run the following commands in the terminal.

1
2
$ sudo apt update
$ sudo apt install xvfb ghostscript

Once the xvfb and ghostscript are installed, we could start any X client in the terminal using xvfb-run.

1
2
$ xvfb-run firefox
$ xvfb-run python plot.py

Conclusions

Xvfb would be very useful for a lot of GUI based simulations running in Docker container or remote server.

References

Author

Lei Mao

Posted on

07-01-2020

Updated on

07-01-2020

Licensed under


Comments