Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Run a GUI application in a Docker container

The main use-case for containers are servers, daemons and applications run in headless mode. However, containers are fully capable of running desktop (GUI) applications in a sandbox. The key to this use-case is the X server running on the host operating system. All we have to do is to run a container as a client to the host's X server to display its GUI. This requires two additional parameters with docker run:

  1. Host shell's display env var: -e DISPLAY=$DISPLAY ( -e DISPLAY also works)
  2. Host machine's X server socket mounted as a volume in the container: -v /tmp/.X11-unix:/tmp/.X11-unix:ro

Build & Run

To build an image from the project root, run command like

docker build -t IMAGE_NAME[:TAG] ./CONTEXT_DIR

For a Firefox image

docker build -t firefox-box:0.1 ./firefox

The xhost program is used to add and delete host names or user names to the list allowed to make connections to the X server. Therefore, in order to allow requests from non-network local connections to the host's X server

xhost + local:root

Finally, we can run a container from this image

docker run --rm -it --name firefox -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:ro firefox-box:0.1

There are a couple of convenience scripts for this this purpose at the project root that can be used as

./build.sh firefox-box:0.1 ./firefox
./run.sh firefox-box:0.1

Docker-Compose

There are also docker-compose.yml provided for each sub-repository that are automated via compose.sh script. Use these scripts from project root as

./firefox/compose.sh

Docker Hub

If you just want to test the image without dirtying your hands, pull the Firefox image hosted at the docker hub and give it a spin.

References

  1. Lei Mao's log book.
  2. linuxmeerkat blog.

About

Run GUI application sand-boxed in a Docker container

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages