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

后端 未结 4 534
予麋鹿
予麋鹿 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: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
    

提交回复
热议问题