简体   繁体   English

GUI 应用程序通过 Docker - X11 - “无法初始化服务器”

[英]GUI application via Docker - X11 - “Unable to init server”

I'm trying to run Firefox in a Debian docker image but can't connect to the X11 server.我正在尝试在 Debian docker 映像中运行 Firefox 但无法连接到 X11 服务器。

I'm using the method described here , but changed the base image to the latest Debian.我正在使用此处描述的方法,但将基础映像更改为最新的 Debian。 I also changed the user creation method.我还更改了用户创建方法。

Dockerfile Dockerfile

FROM debian:latest                                                                 
RUN apt-get update && apt-get install -y firefox-esr
RUN useradd --shell /bin/bash --create-home developer && \
    usermod -aG sudo developer
  
USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

Building the container构建容器

docker build -t firefox .

Command to start the container启动容器的命令

docker run -ti --rm \
   -e DISPLAY=$DISPLAY \
   -v /tmp/.X11-unix:/tmp/.X11-unix \
   firefox

ERROR错误

Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0

Operating system操作系统

OpenSUSE Leap 15.2 OpenSUSE 飞跃 15.2

Context语境

I'm doing the above to understand how to run a GUI app via docker.我这样做是为了了解如何通过 docker 运行 GUI 应用程序。 The aim is to run the latest version of FreeCAD (v19), which is currently broken on OpenSUSE.目的是运行最新版本的 FreeCAD (v19),该版本目前在 OpenSUSE 上被破坏。

docker run --rm \
--net=host \
--env="DISPLAY" \
--volume="$HOME/.Xauthority:/home/developer/.Xauthority:rw" \
firefox

This should work with your Dockerfile!这应该适用于您的 Dockerfile!

Couple of points几点

  • .Xauthority file also needs to be shared as it holds the cookies and auth sessions for the X server. .Xauthority 文件也需要共享,因为它包含 X 服务器的 cookies 和身份验证会话。 Hence it has to be read/write too.因此它也必须是读/写的。
  • If you dont want to do --net=host then you can listen on a TCP port bound to unix socket and forward that to the container.如果你不想做--net=host那么你可以在绑定到 unix 套接字的 TCP 端口上监听并将其转发到容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM