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:
- Host shell's display env var:
-e DISPLAY=$DISPLAY(-e DISPLAYalso works) - Host machine's X server socket mounted as a volume in the container:
-v /tmp/.X11-unix:/tmp/.X11-unix:ro
To build an image from the project root, run command like
docker build -t IMAGE_NAME[:TAG] ./CONTEXT_DIRFor a Firefox image
docker build -t firefox-box:0.1 ./firefoxThe 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:rootFinally, 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.1There 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.1There 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.shIf 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.
- Lei Mao's log book.
- linuxmeerkat blog.