Docker Container GUI Display
Introduction
Docker is typically used for containerized application and development. However, people hardly used it for applications that have GUIs.
It turns out that Docker is fully capable of running GUI applications. In this blog post, I would like to discuss how to run GUI applications from Docker quickly using two simple examples.
Examples
The key to run GUI applications from Docker image is to set -e DISPLAY=$DISPLAY
and -v /tmp/.X11-unix:/tmp/.X11-unix
for Docker container. Also make sure that the X clients can be connected from any host, including our Docker container, by running xhost +
.
I have prepared the Docker containers and running instructions for two GUI applications, Firefox and Chrome.
Firefox
It would be desired if canberra-gtk
libraries are installed in the Docker container. Otherwise warnings might occur. The Dockerfile for Firefox is as follows.
1 | FROM ubuntu:20.04 |
To build the Docker image, please run the following command.
1 | $ docker build -f firefox.Dockerfile -t firefox:0.0.1 . |
To start Firefox from the Docker container, please run the following command..
1 | $ xhost + |
Chrome
The Dockerfile for Chrome is similar to the one for Firefox. Note that to run Chrome from Docker container, we have to use a couple of additional arguments, such as --no-sandbox
, --disable-dev-shm-usage
, and --disable-gpu
.
1 | FROM ubuntu:20.04 |
To build the Docker image, please run the following command.
1 | $ docker build -f chrome.Dockerfile -t chrome:0.0.1 . |
To start Chrome from the Docker container, please run the following command..
1 | $ xhost + |
Display Size
Sometimes, the display size from Docker container is not ideal. We could set the display size using environment variables DISPLAY_WIDTH
and DISPLAY_HEIGHT
.
1 | $ docker run -it --rm -e DISPLAY=$DISPLAY -e DISPLAY_WIDTH=3840 -e DISPLAY_HEIGHT=2160 -v /tmp/.X11-unix:/tmp/.X11-unix firefox:0.0.1 |
References
Docker Container GUI Display