Xt error: Can't open display, if using default DISPLAY

后端 未结 4 520
予麋鹿
予麋鹿 2021-02-05 13:41

Overview

I\'m attempting to get XQuartz to work on OSX so I can do X11 forwarding via Docker. I\'m following the instructions here. I believe my question may be answer

相关标签:
4条回答
  • 2021-02-05 14:24

    I hadn't restarted after re-installing XQuartz. I restarted, and now it works. :).

    0 讨论(0)
  • 2021-02-05 14:34

    Dockerized UI Apps in Docker for Desktop MacOS 2018+

    Went through all the pain to get the simplest version possible that does not depend on checking port, ip, etc... Here it is.

    • Running version XQuartz 2.7.11 (xorg-server 1.18.4)
    • Docker version docker version 18.06.1-ce

    Make sure to install XQuartz

    $ brew install socat
    $ brew cask reinstall xquartz
    
    • Don't forget to close logout and log back in.

    1. Close any 6000

    On a new terminal, verify if there's anything running on port 6000

    $ lsof -i TCP:6000
    $
    

    If there is anything, just kill the process

    2. Close any 6000

    Open a socket on that port and keep the terminal open

    $ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
    

    3. Verify 6000 is open

    In a new terminal, verify if it is opened

    $ lsof -i TCP:6000
    COMMAND   PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    socat   29298 mdesales    5u  IPv4 0xe21e43ca9d99bf1d      0t0  TCP *:6000 (LISTEN)
    

    4. Build and Run simple UI App

    $ cat Dockerfile.eyes
    FROM centos
    RUN yum install -y xeyes
    CMD ["/usr/bin/xeyes"]
    $ docker build -t eyes -f Dockerfile.eyes .
    

    The magic happens using the variables from Docker. Just using the -e DISPLAY=docker.for.mac.host.internal:0 did the trick, as it it will point to the internal IP address and provide that to the docker image. The port forward will do its magic.

    $ docker run -e DISPLAY=docker.for.mac.host.internal:0 eyes
    

    I noticed that at this point XQuartz is opened on it own to the same port

    $ lsof -i TCP:6000
    COMMAND   PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    socat   29298 mdesales    5u  IPv4 0xe21e43ca9d99bf1d      0t0  TCP *:6000 (LISTEN)
    X11.bin 29462 mdesales    8u  IPv6 0xe21e43ca7cdb1135      0t0  TCP *:6000 (LISTEN)
    

    5. Profit and run more apps

    $ docker run -e DISPLAY=docker.for.mac.host.internal:0 jess/tor-browser
    

    $ docker run -e DISPLAY=docker.for.mac.host.internal:0 batmat/docker-eclipse
    

    0 讨论(0)
  • 2021-02-05 14:34

    I needed to quit Terminal and then relaunch it in order to get it to work.

    0 讨论(0)
  • 2021-02-05 14:35

    For OS X 10.6.3 and later, per XQuartz 2.7.11 instructions:

    If this is your first time installing XQuartz, you may wish to logout and log back in. This will update your DISPLAY environment variable to point to XQuartz.app rather than X11.app. If you would prefer to keep using X11.app as your default server (you can still launch XQuartz.app manually), you’ll want to disable /Library/LaunchAgents/org.macosforge.xquartz.startx.plist using launchctl(1).

    After installing XQuartz 2.7.11 on my macOS High Sierra, logging out of my Mac and logging in again was enough for this to work via my MacOS Terminal. However, you may avoid having to logout and log in by opening the XQuartz Terminal application (XQuartz > Applications > Terminal), and running your X application from there. For example:

    enter image description here

    and then

    bash-3.2$ xclock &
    
    0 讨论(0)
提交回复
热议问题