简体   繁体   English

使用X11转发启动并附加Docker容器

[英]Start and attach a docker container with X11 forwarding

There are various articles like this , this and this and many more, that explains how to use X11 forwarding to run GUI apps on Docker. 有喜欢各种物品这个这个这个 ,还有更多,这解释了如何使用X11转发到泊坞运行GUI应用。 I am using a Centos Docker container. 我正在使用Centos Docker容器。

However, all of these approaches use 但是,所有这些方法都使用

docker run

with all appropriate options in order to visualize the result. 带有所有适当的选项,以便可视化结果。 Any use of docker run creates a new image and performs the operation on top of that. docker run任何使用都会创建一个新映像,并在此映像之上执行操作。

A way to work in the same container is to use docker start followed by docker attach and then executing the commands on the prompt of the container. 在同一个容器中工作的一种方法是先使用docker start ,再使用docker attach ,然后在容器提示下执行命令。 Additionally, the script (let's say xyz.sh) that I intend to run on Docker container resides inside a folder MyFiles in the root directory of the container and accepts a parameter as well 此外,我打算在Docker容器上运行的脚本(假设为xyz.sh)位于容器根目录下的MyFiles文件夹中,并且也接受参数

So is there a way to run the script using docker start and/or docker attach while also X11-forwarding it? 那么有没有一种方法可以使用docker start和/或docker attach运行脚本,同时也可以X11转发它?

This is what I have tried, although would like to avoid docker run and instead use docker start and docker attach 这是我尝试过的方法, 尽管要避免docker run ,而是使用docker startdocker attach

sudo docker run -it \
    --env="DISPLAY" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    centos \
    cd MyFiles \
    ./xyz.sh param1
export containerId='docker ps -l -q'

This in turn throws up an error as below - 反过来会引发如下错误:

/usr/bin/cd: line 2: cd: MyFiles/: No such file or directory
  1. How can I run the script xyz.sh under MyFiles on the Docker container using docker start and docker attach ? 如何运行使用泊坞容器下MYFILES脚本xyz.sh docker startdocker attach

  2. Also since the location and the name of the script may vary, I would like to know if it is mandatory to include each of these path in the system path variable on the Docker container or can it be done at runtime also? 另外,由于脚本的位置和名称可能会有所不同,所以我想知道是否必须在Docker容器的系统路径变量中包含每个路径,还是可以在运行时完成?

It looks to me your problem is not with X11 forwarding but with general Docker syntax. 在我看来,您的问题不是X11转发,而是通用Docker语法。

You could do it rather simply: 您可以简单地做到这一点:

sudo docker run -it \
    --env="DISPLAY" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    -w MyFiles \
    --rm \
    centos \
    bash -c xyz.sh param1

I added: 我补充说:

  • --rm to avoid stacking old dead containers. --rm以避免堆积旧的死容器。
  • -w workdir , obvious meaning -w workdir ,很明显的意思
  • /bin/bash -c to get sure your script is interpreted by bash. /bin/bash -c确保您的脚本被bash解释。

How to do without docker run : 没有docker run怎么办:

run is actually like create then start . run实际上就像create然后start You can split it in two steps if you prefer. 如果愿意,可以将其分为两个步骤。

If you want to attach to a container, it must be running first. 如果要附加到容器,则必须先运行它。 And for it to be running, there must be a process currently running inside. 为了使其运行,当前必须在其中运行一个进程。

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

相关问题 Docker 容器中 GUI 应用程序的 X11 转发 - X11 forwarding of GUI app in Docker container 使用PyCharm和Docker Interpreter转发X11 - X11 forwarding with PyCharm and Docker Interpreter 具有X11转发的Docker中的电子 - 未指定协议 - Electron inside Docker with X11 Forwarding - No Protocol Specified 使用X11转发在Docker中运行多个GUI - Running multiple GUIs in Docker using X11 forwarding 在 docker 中运行的 GUI 应用程序的 X11 转发 - X11 forwarding of a GUI app running in docker 具有共享X11套接字的Docker:为什么它可以在容器外部“启动” Firefox? - Docker with shared X11 socket: Why can it “start” Firefox outside of the container? 如何在Jenkins声明式管道中将x11转发到Docker容器 - How to forward x11 to Docker container in Jenkins declarative pipeline 无法在 docker 中使用 X11 启动多个进程 - Cannot start multiple processes with X11 in docker 我们可以构建支持GUI的基本docker镜像(NO X11转发)吗? - Can we build base docker images which are GUI enabled (NO X11 forwarding)? 当映像在docker机器上运行时X11转发不起作用,但是如果映像在docker机器上运行则可以正常工作 - X11 forwarding doesn’t work when image runs in docker machine but it works fine if the image is run w/o a docker machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM