简体   繁体   English

在 Windows 10 上的 Docker 容器中运行 X-Windows 桌面应用程序

[英]Running X-Windows Desktop Apps in Docker Containers on Windows 10

I want to have a Linux development environment (Java, Intellij Idea, Clojure and ClojureScript) in my Windows 10 machine (i5, 8GB, 240 GB ssd, 2&1 notebook).我想在我的 Windows 10 机器(i5、8GB、240 GB ssd、2&1 笔记本)中有一个 Linux 开发环境(Java、Intellij Idea、Clojure 和 ClojureScript)。 I can use:我可以用:

  1. a Linux VM (using Hyper-V, VMware Player or Virtual Box), or Linux VM(使用 Hyper-V、VMware Player 或 Virtual Box),或
  2. a docker container running desktop apps.运行桌面应用程序的 docker 容器。

I would like to try the second option.我想尝试第二种选择。 In Docker Containers on the Desktop , the author runs a Chrome browser docker using:桌面上的 Docker Containers 中,作者使用以下命令运行 C​​hrome 浏览器 docker:

$ docker run -it \
--net host \ # may as well YOLO
--cpuset-cpus 0 \ # control the cpu
--memory 512mb \ # max memory it can use
-v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
-e DISPLAY=unix$DISPLAY \ # pass the display
-v $HOME/Downloads:/root/Downloads \ # optional, but nice
-v $HOME/.config/google-chrome/:/data \ # if you want to save state
--device /dev/snd \ # so we have sound
--name chrome \
jess/chrome

The Dockerfile he used can be adapted to run other desktop apps, but the command above doesn't work in Windows.他使用的 Dockerfile 可以适应运行其他桌面应用程序,但上面的命令在 Windows 中不起作用。 I have a XWindows server running (in Windows 10), but I would like to know how to change -e DISPLAY=unix$DISPLAY and --device /dev/snd options.我有一个 XWindows 服务器正在运行(在 Windows 10 中),但我想知道如何更改-e DISPLAY=unix$DISPLAY--device /dev/snd选项。 How can this command be changed to work?如何更改此命令才能工作?

Docker runs in Windows using a Hyper-V Linux VM. Docker 使用 Hyper-V Linux VM 在 Windows 中运行。 Is it going to be faster than a full Linux VM in Hyper-V (or other VM system) or is modularity the only advantage of docker in this case?它会比 Hyper-V(或其他 VM 系统)中的完整 Linux VM 更快,还是模块化是 docker 在这种情况下的唯一优势?

The following command works (I'm using XcXsrv Xserver allowing connections from any source):以下命令有效(我使用XcXsrv Xserver 允许来自任何来源的连接):

docker run -d --name firefox1 -e DISPLAY=your-machine-ip-address:0  jess/firefox

You can drop --name firefox1 if you don't want to name the docker.如果您不想命名--name firefox1您可以删除--name firefox1 Movies work fine but with no sound.电影工作正常,但没有声音。 Does anyone can help here?有人可以在这里帮忙吗?

Other Xservers should work as well, just make sure you allow connections from any sources (be careful, this setup can be a security threat in open networks).其他 Xservers 应该也能工作,只要确保你允许来自任何来源的连接(小心,这种设置在开放网络中可能是一个安全威胁)。

Remember that your docker container and your host are virtually different machines.请记住,您的 docker 容器和您的主机实际上是不同的机器。 To use a GUI application from your docker container is exactly the same of running a Linux GUI application on a remote host and displaying it on your local Windows host.从 docker 容器使用 GUI 应用程序与在远程主机上运行 Linux GUI 应用程序并将其显示在本地 Windows 主机上完全相同。

When your host is a Linux machine, that's pretty easy.当您的主机是 Linux 机器时,这很容易。 Your host already runs an X server.您的主机已经运行了 X 服务器。 The docker container can export its X display to the host and use host's X server to run GUI applications. docker 容器可以将其 X 显示导出到主机,并使用主机的 X 服务器运行 GUI 应用程序。 That's what your docker command does.这就是你的 docker 命令所做的。

With a Windows host there is no such possibility since it does not run X, so there is no slight modification that can achieve what you want.对于 Windows 主机,则没有这种可能性,因为它不运行 X,因此没有可以实现您想要的任何轻微修改。

Your options are either running X server on Windows by using some third party tools, or using any other remote connection technology, such as VNC or RDP.您可以选择使用某些第三方工具在 Windows 上运行 X 服务器,或者使用任何其他远程连接技术,例如 VNC 或 RDP。 But since you want a development environment, I guess you want a seamless experience and a VNC or RDP window won't work.但是既然你想要一个开发环境,我猜你想要一个无缝的体验,而 VNC 或 RDP 窗口将不起作用。 Then you should go for running an X server on Windows.然后你应该去在 Windows 上运行一个 X 服务器。

Check out this answer for a possible way to achieve this.查看此答案以了解实现这一目标的可能方法。 Also please read other answers to the question.另请阅读该问题的其他答案。 There might be security implications of using the host X server for docker container apps.将主机 X 服务器用于 docker 容器应用程序可能存在安全隐患。 Since you are using host X server, applications are not truly sandboxed anymore.由于您使用的是主机 X 服务器,应用程序不再是真正的沙盒。

I had the same problem and I needed a couple more steps.我有同样的问题,我需要更多的步骤。

The docker file is almost the same: docker 文件几乎相同:

FROM ubuntu:18.04

RUN apt-get update && apt-get install -y firefox

# Replace 1000 with your user / group id
RUN export uid=1000 gid=1000 && \
    mkdir -p /home/developer && \
    echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
    echo "developer:x:${uid}:" >> /etc/group && \
    echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
    chmod 0440 /etc/sudoers.d/developer && \
    chown ${uid}:${gid} -R /home/developer

USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

The build was:构建是:

cat firefox.dockerfile | docker build -t firefox -

Then I had to open my x server to accept connections with:然后我不得不打开我的 x 服务器来接受与以下内容的连接:

xhost +

And finally I had to run the container with the option of running in the same network as the host:最后,我必须运行容器,并选择在与主机相同的网络中运行:

docker run --net host -e DISPLAY=$DISPLAY firefox

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

相关问题 如何提高在 Windows 10 上运行 R 脚本的基于 Linux 的 Docker 桌面容器的性能? - How can I improve the performance of Linux-based Docker Desktop containers running R scripts on Windows 10? In Docker Desktop for windows 10 with WSL2, where does docker containers live & how Linux containers can run a java app, but not windows nanoserver? - In Docker Desktop for windows 10 with WSL2, where does docker containers live & how Linux containers can run a java app, but not windows nanoserver? 如何在 X-Windows 中改变焦点? - How to change focus in X-Windows? 参考 Windows 容器的名称来自 Docker 桌面中的 Linux 容器 - Reference Windows containers by name from Linux containers in Docker Desktop 如何创建独立于当前窗口管理器的X-windows窗口? - How do I create a X-windows window independent of the current window manager? Docker 复制 - Windows 10 - Docker COPY - Windows 10 当 docker 桌面在 linux 上运行时,Docker 图像和容器发生变化 - Docker images and containers change when docker desktop is running on linux Windows 上的 Linux 容器 (LCOW) 功能与在 Windows 上运行 Linux VM - Linux Containers on Windows (LCOW) feature vs Running Linux VM on Windows 在docker窗口上运行linux容器 - Running linux container on docker windows 无法在 Windows 10 上构建 Docker 映像 - Unable to build a Docker image on Windows 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM