Problem

You want to run a GUI application, for instance Firefox, in your Docker container for Mac and have it forwarded to your Macbook.

Solution

TLDR version

If you just want to copy paste:

IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $IP
docker run --rm -it -e DISPLAY=${IP}:0 -v /tmp/.X11-unix:/tmp/.X11-unix selenium/standalone-firefox firefox

:)

Step-by-step explanation

This can be achieved via XQuartz on Mac.

  1. Install XQuarts: https://www.xquartz.org/ (yes, the release date is a couple of years old, I was also surprised)
  2. Open it and activated "Allow connections from network clients" under Preferences > Security
  3. Reboot your Macbook
  4. Start XQuartz
  5. Allow connections from your Macbook's IP
  • IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
  • xhost + $IP

6. Start Firefox inside your docker container:

  • docker run --rm -it -e DISPLAY=${IP}:0 -v /tmp/.X11-unix:/tmp/.X11-unix selenium/standalone-firefox firefox

That's it.

References

Getagged mit:
Docker Tutorial
blog comments powered by Disqus