How to forward Docker for Mac to X11?

Using Docker for Mac 1.12 (stable) and OS X 10.11.5 (15F34), I’m attempting to make one of my containers forward to X11.

First, I install XQuartz from my bash shell:

  • When restart docker.io service,some docker containers don't start
  • Docker Expose ports dynamically
  • Docker - Creating multiple containers/environments with different versions
  • How to use Moby to create a custom made container system?
  • How to get elasticsearch to work in ubuntu docker container
  • Kubernetes - How to run kubectl commands inside a container?
  • $ brew cask install xquartz
    
    ==> Downloading https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.9.dmg
    ######################################################################## 100.0%
    ==> Verifying checksum for Cask xquartz
    ==> Running installer for xquartz; your password may be necessary.
    ==> Package installers may write to any location; options such as --appdir are ignored.
    Password:
    ==> installer: Package name is XQuartz 2.7.9
    ==> installer: Installing at base path /
    ==> installer: The install was successful.
    🍺  xquartz staged at '/usr/local/Caskroom/xquartz/2.7.9' (73M)
    

    Then I continue with setting up XQuartz…

    open -a XQuartz
    

    In the XQuartz Preferences -> Security tab, I enable “Allow connections from network clients”.

    Then I am supposed to run xhost + $MY_IP_ADDRESS in my bash shell, but all I get is this error:

    xhost:  unable to open display ""
    

    In the end, all guides I’m reading says I should run my container like this:

    docker run -e DISPLAY=$MY_IP_ADDRESS:0 -v /tmp/.X11-unix:/tmp/.X11-unix DOCKER_IMAGE
    

    …but that doesn’t work. In my particular container, I get this error:

    ... cannot connect to X server 10.0.0.131:0
    

    What am I doing wrong?

  • docker-compose tries to access registry v1 on first “up”
  • Connect PostgreSQL server running in docker container to wild-fly docker container?
  • Docker, I have one folder that contains the application server. What can be used as a container?
  • How to properly run migrations and seed a docker MySql DB using Entity Framework Core
  • How to install pdo driver in php docker image?
  • Openshift Origin run-app against insecure registry yields stuck pod with “Error while pulling image”
  • 2 Solutions collect form web for “How to forward Docker for Mac to X11?”

    Turns out there’s a bug in XQuartz 2.7.9.

    When using XQuartz 2.7.10_beta2, it works.

    I have xQuartz 2.7.11 installed on Mac OS.

    I was getting the following error

    <program>: cannot connect to X server <ip>:0

    when trying to run docker container. I tried downgrading XQuartz but it still didn’t fix my issue.

    A crucial piece to to the setup is to add your ip access control list for xhost.

    xhost + $(ipconfig getifaddr en0)

    After adding the ip to xhost, everything works. There is no need to downgrade Xquartz version.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.