[英]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 start
和docker 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
How can I run the script xyz.sh under MyFiles on the Docker container using docker start
and docker attach
? 如何运行使用泊坞容器下MYFILES脚本xyz.sh
docker start
和docker attach
?
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.