Skip to content

Instantly share code, notes, and snippets.

@eshnil2000
Created January 14, 2023 04:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eshnil2000/dd71024b315e2d6d0953d6227569546b to your computer and use it in GitHub Desktop.
Save eshnil2000/dd71024b315e2d6d0953d6227569546b to your computer and use it in GitHub Desktop.
docker_gui_display.txt
Docker Container GUI Display
https://leimao.github.io/blog/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.
firefox.Dockerfile
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get -y install \
firefox \
libcanberra-gtk-module \
libcanberra-gtk3-module
RUN apt-get clean
CMD ["firefox"]
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..
$ xhost +
$ docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox:0.0.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.
chrome.Dockerfile
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y \
wget \
libcanberra-gtk-module \
libcanberra-gtk3-module
RUN apt-get clean
RUN cd /tmp && \
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt-get install -y ./google-chrome-stable_current_amd64.deb
CMD ["google-chrome", "--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"]
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
2
3
$ xhost +
$ docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix chrome:0.0.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:/t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment