Setup XQuartz X11 server on MacΒΆ

The XQuartz X11 server will be used to allow us visualise GUI programs, which are running inside the Docker container, on the host Mac machine. The following guide has been adapted from this link.

  1. Install XQuartz

    1. From the XQuartz website

    2. Using homebrew

      brew cask install xquartz
      
  2. Run XQuartz

    1. Start XQuartz from command line using:

      open -a XQuartz
      
    2. In the XQuartz preferences, go to the Security tab and make sure Allow connections from network clients is ticked.

    3. Exit and restart XQuartz to allow the updated preferences to take affect.

  3. Identify and add your Host Machine IP to Xhost

    1. Run the following command in a terminal to find your Host Machine IP:

      IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
      
    2. Check if the IP enviromental variable has been set correctly:

      echo $IP
      

      If blank and you are on wifi, try en1 instead of en0 in Step (i).

    3. Add the IP using Xhost:

      xhost + $IP
      

      If this produces an error, try:

      /usr/X11/bin/xhost + $IP