Skip to content

Instantly share code, notes, and snippets.

@dahlia
Last active March 13, 2021 08:10
Show Gist options
  • Save dahlia/4e8dc41ff29a86d08790589ca6f66174 to your computer and use it in GitHub Desktop.
Save dahlia/4e8dc41ff29a86d08790589ca6f66174 to your computer and use it in GitHub Desktop.
Running X11 GUI apps through Docker + XQuartz on macOS

Running X11 GUI apps through Docker + XQuartz on macOS

Prerequisites

  • Docker
  • socat
  • XQuartz
brew cask install docker xquartz
brew install socat

Preparing an image

docker build -t x-firefox .

Forwarding X11 socket insisde the container to the macOS host

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-
xhost + "$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')"

Running an image

Run the following command on xterm (provided by XQuartz):

docker run \
    --rm \
    -e DISPLAY="$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')":0 \
    -v $HOME/Downloads:/root/Downloads \
    x-firefox
FROM ubuntu:17.10
# We don't optimize the size of fslayer here...
RUN apt-get update
RUN apt-get install -y \
software-properties-common \
ttf-ubuntu-font-family \
fonts-ubuntu-title \
fonts-ubuntu-font-family-console
RUN add-apt-repository -y \
ppa:ubuntu-mozilla-daily/firefox-aurora
RUN apt-get update
RUN apt-get install -y firefox
CMD firefox --new-instance https://hongminhee.org/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment