I'd like to run an application in a Docker container that can start a GUI. This guide recommends using XQuartz. After starting XQuartz, run the following:

ip=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $ip
docker run -d --name firefox -e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix jess/firefox

This gives your local device permission to access the host server. Running the above, I get the error:

cannot connect to X server
  • Please expand on what you are doing and what you have tried to fix the problem. Your question is far too brief in detail. – Tony Williams Jun 18 '18 at 10:05

I was not using the right display number. The guide above uses the default display number :0.

Find the correct one by running:

  display_number=`ps -ef | grep "Xquartz :\d" | grep -v xinit | awk '{ print $9; }'`

Then change your docker run command to include the flags:

-e DISPLAY=$ip:$display_number \
-v /tmp/.X11-unix:/tmp/.X11-unix \

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .