简体   繁体   English

如何从jenkins SSH进入运行的docker容器执行shell

[英]How to SSH into running docker container from jenkins execute shell

I am running a docker container ( dind ) from jenkins execute shell 我正在从jenkins execute shell运行dind容器( dind

CONTAINER_ID="$(sudo docker run --privileged -i -d jpetazzo/dind)"

To execute docker commands inside container I get into container shell 要在容器内执行docker命令,请进入容器外壳

sudo docker exec -it --privileged ${CONTAINER_ID} bash

and than I am trying to execute these commands inside dind container. 并且比我试图在dind容器内执行这些命令。

sudo docker pull hubuser/hello-world

sudo docker run hubuser/hello-world

sudo docker tag imageId hubuser/hello-world:123

sudo docker login --username=hubuser --password=password

sudo docker push hubuser/hello-world

All of these 7 commands I have written in jenkins execute shell. 我在jenkins中编写的所有这7条命令都执行外壳。 Below given 5 commands are executing outside dind container, not inside. 下面给出的5条命令在dind容器外部dind不是内部执行。 If I am trying from terminal than it is attaching to the container shell and executing properly. 如果我从终端尝试,则它是附加到容器外壳并正确执行。 I want to execute them inside container but from jenkins. 我想在容器中执行它们,但要从詹金斯执行。 I also tried adding exec before every command like this: 我还尝试在每个命令之前添加exec ,如下所示:

sudo docker exec -it --privileged ${CONTAINER_ID} sudo docker pull hubuser/hello-world

sudo docker exec -it --privileged ${CONTAINER_ID} sudo docker run hubuser/hello-world

and so on. 等等。 This executes commands inside dind container but all commands executes in parallel, so before pulling and running the hello-world image, it tries to tag it and push it. 这会在dind容器内执行命令,但所有命令都是并行执行的,因此在拉出并运行hello-world映像之前,它会尝试对其进行标记和推送。 There it is not finding any hello-world image to tag and it does't do anything. 在那里,它找不到任何要标记的hello-world图像,并且不执行任何操作。

I want all my below 5 commands to execute serially inside dind container, that too from jenkins execute shell. 我希望所有下面的5条命令在dind容器内dind执行,同样也要从jenkins execute shell中执行。

The title of your post is "how to ssh into running docker". 您的帖子标题是“如何SSH进入正在运行的docker”。 I just want to point out this article, wrote by a Docker engineer: If you run SSHD in your Docker containers, you're doing it wrong! 我只想指出这篇由Docker工程师撰写的文章: 如果在Docker容器中运行SSHD,那么您做错了!

After I read your post, that is not treating issue with ssh, I just thought about: why not execute a bash-script that does sequentially what you wanted to? 看完您的文章后,那不是用ssh解决问题,我只是想:为什么不执行顺序执行您想要的bash脚本?

I'm not sure if I understood well btw, is Jenkins inside a docker? 我不确定我是否很好理解,詹金斯在码头工人内部吗? Are you running a docker in a docker? 您是否正在docker中运行docker?

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

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