Skip to content

dmotte/docker-xfwd

Repository files navigation

docker-xfwd

GitHub main workflow Docker Pulls

🐳 Run graphical applications in a Docker container.

📦 This image is also on Docker Hub as dmotte/xfwd and runs on several architectures (e.g. amd64, arm64, ...). To see the full list of supported platforms, please refer to the .github/workflows/main.yml file. If you need an architecture which is currently unsupported, feel free to open an issue.

Simple usage

The simplest way to try this image is:

docker run -d --name=xfwd01 -v/tmp/.X11-unix/X0:/opt/xfwd/host.sock:ro -v"${XAUTHORITY:?}:/opt/xfwd/host.xauth:ro" dmotte/xfwd

Then you can install and run some graphical application inside the container:

docker exec -it xfwd01 bash -ec 'apt-get update; apt-get install -y x11-apps'
docker exec -it -{u,eUSER=}mainuser -{eHOME=,w}/home/mainuser xfwd01 xclock

Screenshot

Standard usage

The docker-compose.yml file contains a complete usage example for this image. Feel free to simplify it and adapt it to your needs. Unless you want to build the image from scratch, comment out the build: build line to use the pre-built one from Docker Hub instead.

To start the Docker-Compose stack in daemon (detached) mode:

docker-compose up -d

Then you can view the logs using this command:

docker-compose logs -ft

Then you can install and run some graphical application inside the container:

docker-compose exec main bash -ec 'apt-get update; apt-get install -y x11-apps'
docker-compose exec -{u,eUSER=}mainuser -{eHOME=,w}/home/mainuser main xclock

This image supports running commands at container startup by mounting custom scripts at /opt/startup-early/*.sh and /opt/startup-late/*.sh. This is the same approach used by dmotte/desktainer.

Environment variables

List of supported environment variables:

Variable Required Description
MAINUSER_NAME No (default: mainuser) Name of the main user
MAINUSER_NOPASSWORD No (default: false) Whether or not the main user should be allowed to sudo without password

Development

If you want to contribute to this project, you can use the following one-liner to rebuild the image and bring up the Docker-Compose stack every time you make a change to the code:

docker-compose down && docker-compose up --build

Note: I know that this Docker image has many layers, but this shouldn't be a problem in most cases. If you want to reduce its number of layers, there are several techniques out there, e.g. see this