如何在Docker中的Ubuntu上运行xeyes?

huangapple go评论61阅读模式
英文:

How to run xeyes in Docker Ubuntu?

问题

我的目标是进行X11转发。第一步是确保xeyes能正常运行。然而,当我尝试运行xeyes时,它报错:

以下是错误命令部分的翻译:

(base) jason@Jasons-Mac-mini darkmark-docker-web % docker run -it --rm --net=host -e DISPLAY -v $HOME/.Xauthority:/root/.Xauthority  my-xeyes
Error: 无法打开显示:/private/tmp/com.apple.launchd.abcde/org.xquartz:0

以下是Dockerfile部分的翻译:

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
英文:

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

答案1

得分: 0

我有两种方法可以做。我使用 alpine 但它仍然通过 XQuartz 提供 X11。

两种方法都经过测试,使用以下环境:

  • macOS Ventura 13.1
  • Docker Desktop 14.6.2
  • XQuartz 2.8.2

这个方法需要 socat

# 安装 socat 和 XQuartz
brew install socat
brew cask install xquartz

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

# 确保 XQuartz 和 Docker 已启动 - 你也可以通过图形界面完成
open -a XQuartz
open -a docker

# 运行 alpine latest
docker run -it -e DISPLAY=host.docker.internal:0 alpine:latest

# 在 Docker 容器内部安装并运行 xeyes
/ # apk update && apk add xeyes && xeyes

这个方法不需要 socat

# 启动 XQuartz - 也可以通过 Spotlight 搜索完成
open -a XQuartz

前往 XQuartz->设置->安全,勾选 "认证连接""允许来自网络客户端的连接"

停止并重新启动 XQuartz - 等待它运行

xhost + $(hostname)
MarkBookPro.local 被添加到访问控制列表

# 启动 alpine 镜像
docker run --rm -e DISPLAY=host.docker.internal:0 -it alpine

# 在 Docker 容器内部安装并运行 xeyes
/ # apk update && apk add xeyes && xeyes
英文:

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

huangapple
  • 本文由 发表于 2023年2月8日 20:58:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386154.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定