Skip to content

Instantly share code, notes, and snippets.

@twizmwazin
Created January 17, 2025 19:40
Show Gist options
  • Select an option

  • Save twizmwazin/c4842ea1805f34e2ab0fb050d88eecc5 to your computer and use it in GitHub Desktop.

Select an option

Save twizmwazin/c4842ea1805f34e2ab0fb050d88eecc5 to your computer and use it in GitHub Desktop.
X11 Docker example

X11 Docker Example

Take the following dockerfile:

FROM debian:bookworm
RUN apt-get update && apt-get install -y firefox-esr
CMD firefox

Build it with: docker build . -t firefox

Run the container like this:

xhost +  # Disables X server authorization. Run `xhost -` later to turn auth back on
docker run -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox
@tiffanyb

Copy link
Copy Markdown

You can follow this for a vanilla Mac:

Install XQuartz if you haven't already:

brew install --cask xquartz

Launch XQuartz:

open -a XQuartz

In XQuartz preferences, go to the Security tab and ensure "Allow connections from network clients" is checked46.

Restart XQuartz for the changes to take effect.
Allow connections to your local X server:

xhost + localhost

Identify your host machine's IP address:

IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')

Add the IP to the X server's access control list:

xhost + $IP

Run your Docker container with the following modifications:

docker run -e DISPLAY=host.docker.internal:0 -v /tmp/.X11-unix:/tmp/.X11-unix firefox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment