Issue
My goal is to do X11 forwarding. The first step is to make sure xeyes works. However, when I tried to run xeyes, it throws error
The command
(base) jason@Jasons-Mac-mini darkmark-docker-web % docker run -it --rm --net=host -e DISPLAY -v $HOME/.Xauthority:/root/.Xauthority my-xeyes
Error: Can't open display: /private/tmp/com.apple.launchd.abcde/org.xquartz:0
FROM debian:latest
RUN apt-get update && apt-get install -y \
x11-apps \
&& rm -rf /usr/share/doc/* && \
rm -rf /usr/share/info/* && \
rm -rf /tmp/* && \
rm -rf /var/tmp/*
RUN useradd -ms /bin/bash user
USER user
CMD xeyes
Solution
I can do it two ways. I use alpine
but it is still X11 provided via XQuartz.
Both methods tested with:
- macOS Ventura 13.1
- Docker Desktop 14.6.2
- XQuartz 2.8.2
This one needs socat
:
# Install socat and XQuartz
brew install socat
brew cask install xquartz
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" &
# Ensure XQuartz and docker are started - you can do this graphically too
open -a XQuartz
open -a docker
# Run alpine latest
docker run -it -e DISPLAY=host.docker.internal:0 alpine:latest
# Inside docker container. Install and run xeyes
/ # apk update && apk add xeyes && xeyes
This one doesn't need socat
:
# Start XQuartz - could equally do it with Spotlight Search
open -a XQuartz
Goto XQuartz->Settings->Security and check "Authenticate Connections" and "Allow connections from network clients"
Stop and restart XQuartz - wait till it is running
xhost + $(hostname)
MarkBookPro.local being added to access control list
# Start alpine image
docker run --rm -e DISPLAY=host.docker.internal:0 -it alpine
# Inside docker container. Install and run xeyes
/ # apk update && apk add xeyes && xeyes
Answered By - Mark Setchell Answer Checked By - Timothy Miller (WPSolving Admin)