gpt4 book ai didi

How to show GUI apps from docker desktop container on windows 11(如何在Windows 11上显示停靠桌面容器中的图形用户界面应用程序)

转载 作者:bug小助手 更新时间:2023-10-25 16:00:31 31 4
gpt4 key购买 nike



From this article, it states that windows 11 natively supports running of X11 and wayland applications on wsl.

本文指出,Windows11本身就支持在WSL上运行X11和Wayland应用程序。


I tried to do the same through a docker container, setting the environment variable DISPLAY="host.docker.internal:0.0", and running a GUI application (like gedit). But instead I got this error:

我尝试通过停靠容器执行相同的操作,设置环境变量DISPLAY=“Host.docker.Internal:0.0”,并运行一个图形用户界面应用程序(如Gedit)。但我得到的却是这样的错误:


Unable to init server: Could not connect: Connection refused

Gtk-WARNING **: 17:05:50.416: cannot open display: host.docker.internal:0.0

更多回答
优秀答案推荐

I stumbled upon your question while attempting the same thing as you are and actually got it to work with the aid of this blog post on Microsoft. I use a minimal Dockerfile based on Ubuntu and install gedit:

我在尝试和你一样的事情时偶然发现了你的问题,并在这篇关于微软的博客文章的帮助下实际上让它发挥了作用。我使用一个基于Ubuntu的最小Dockerfile并安装Gedit:


FROM ubuntu:22.04
RUN apt update -y && apt install -y gedit
CMD ["gedit"]

Create the image the usual way, e.g. docker build . -t guitest:1.0

以通常的方式创建映像,例如扩展坞构建。-T吉他:1.0


On the WSL command line, start it like this:

在WSL命令行上,按如下方式启动:


docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix \
-v /mnt/wslg:/mnt/wslg \
-e DISPLAY \
-e WAYLAND_DISPLAY \
-e XDG_RUNTIME_DIR \
-e PULSE_SERVER \
guitest:1.0

I hope this is to good use for you as well.

我希望这对你也有很好的帮助。



This answer is heavily based on what chrillof has said. Thanks for the excellent start!

这个答案在很大程度上是基于克里洛夫的说法。感谢您的出色开局!


The critical things here for Docker Desktop users on Windows with WSL2 are that:

对于安装了WSL2的Windows上的Docker Desktop用户来说,这里的关键是:



  1. The container host (i.e. docker-desktop-data WSL2 distribution) does not have a /tmp/.X11-unix itself. This folder is actually found in the /mnt/host/wslg/.X11-unix folder on the docker-desktop distribution which translates to /run/desktop/mnt/host/wslg/.X11-unix when running containers.

  2. There are no baked-in environment variables to assist you, so you need to specify the environment variables explicitly with these folders in mind.


I found this GitHub issue where someone had to manually set environment variables which allowed me to connect the dots between what others experience directly on WSL2 and chrillof's solution

我发现了GitHub的这个问题,有人必须手动设置环境变量,这让我可以将其他人直接在WSL2上体验的内容与chrillof的解决方案联系起来


Therefore, modifying chrillof's solution using PowerShell from the host, it looks more like:

因此,从主机使用PowerShell修改chrillof的解决方案,看起来更像是:


docker run -it -v /run/desktop/mnt/host/wslg/.X11-unix:/tmp/.X11-unix `
-v /run/desktop/mnt/host/wslg:/mnt/wslg `
-e DISPLAY=:0 `
-e WAYLAND_DISPLAY=wayland-0 `
-e XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir `
-e PULSE_SERVER=/mnt/wslg/PulseServer `
guitest:1.0

On my computer, it looks like this (demo of WSLg X11)

在我的电脑上,它看起来像这样(WSLg X11的演示)


To be clear, I have not checked if audio is functional or not, but this does allow you to avoid the installation of another X11 server if you already have WSL2 installed.

需要明确的是,我没有检查音频是否正常工作,但这确实允许您避免安装另一个X11服务器,如果您已经安装了WSL2的话。



Not sure if it helps you, but I'm using Xlaunch for UI in docker. Here is an example of usage gui app in docker

不确定它是否对您有帮助,但我在docker中使用XLaunch for UI。以下是在docker中使用gui应用程序的一个示例


更多回答

am i right to say that for this to work, we have to run docker from a install distro on WSL, instead of running docker from docker desktop?

我们必须在WSL上的安装版本中运行docker,而不是从docker桌面运行docker,这样说对吗?

I ran it on an installed distro in WSL. I don't know how the interaction is with docker desktop, however, I'm pretty sure it was visible from the docker desktop gui as a running container as well

我在WSL的已安装发行版上运行了它。我不知道与docker桌面的交互是如何的,但是,我非常确定它也可以作为运行容器从docker桌面gui上看到。

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

正如它目前所写的,你的答案并不清楚。请编辑以添加更多详细信息,以帮助其他人了解这是如何解决提出的问题的。你可以在帮助中心找到更多关于如何写出好答案的信息。

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

虽然这个链接可能会回答这个问题,但最好在这里包括答案的基本部分,并提供链接以供参考。如果链接的页面发生更改,仅限链接的答案可能会无效。-摘自评论

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com