简体   繁体   English

如何在 Jenkins 中使用 shell 命令启动 docker 容器

[英]How to start docker containers using shell commands in Jenkins

I'm trying to start two containers (each with different image) using Jenkins shell commands.我正在尝试使用 Jenkins shell 命令启动两个容器(每个容器都有不同的图像)。 I tried installing docker extension in Jenkins and/or setting docker in global configuration tools.我尝试在 Jenkins 中安装 docker 扩展和/或在全局配置工具中设置 docker。 I am also doing all this in a pipeline.我也在管道中做这一切。 After executing docker run... I'm getting Docker: not found error in Jenkins console output.执行docker run...我收到Docker: not found error在 Jenkins 控制台输出中。

I am also having a hard time finding a guide on the internet that describes exactly what I wish to accomplish.我也很难在互联网上找到准确描述我希望完成的任务的指南。 If it is of any importance, I'm trying to start a Selenium Grid and a Selenium Chrome Node and then using maven (that is configured and works correctly) send a test suite on that node.如果它有任何重要性,我正在尝试启动一个 Selenium Grid 和一个 Selenium Chrome 节点,然后使用 maven(已配置并正常工作)在该节点上发送一个测试套件。

If u have any experience with something similiar to what I wish to accomplish, please share your thoughts as what the best approach is to this situation.如果您有任何与我希望完成的事情类似的事情的经验,请分享您的想法,了解这种情况的最佳方法是什么。

Cheers.干杯。

That's because docker images that you probably create within your pipeline cannot also run (become containers) within the pipeline environment, because that environment isn't designed to also host applications.那是因为您可能在管道中创建的 docker 映像也不能在管道环境中运行(成为容器),因为该环境不是为托管应用程序而设计的。

You need to find a hosting provider for your docker images (eg Azure or GCP).您需要为您的 docker 映像(例如 Azure 或 GCP)找到托管服务提供商。 Once you set up the hosting part, you need to add a step to your pipeline to upload/push the image to that provider's docker registry or to the free public Docker Hub.设置托管部分后,您需要向管道添加一个步骤,以将图像上传/推送到该提供商的 docker 注册表或免费的公共 Docker Hub。 Then, finally, add a step to your pipeline to send a command to your hosting, to download the image from whichever docker registry you chose, and to launch the image into a container (this last part of download and launch is covered by docker run ).然后,最后,在您的管道中添加一个步骤,向您的主机发送命令,从您选择的任何 docker 注册表下载图像,并将图像启动到容器中(下载和启动的最后一部分由docker run覆盖)。 Only at that point you have a running app.只有在那时,您才有了一个正在运行的应用程序。

Good luck.祝你好运。

Somewhat relevant (maybe it'll help you understand how some of those things work):有点相关(也许它会帮助你理解其中一些事情是如何工作的):

Command docker build is comparable to the proces of producing an installer package such as MSI.命令docker build类似于生成安装程序包(例如 MSI)的过程。

Docker image is comparable to an installation package (eg MSI). Docker 镜像相当于一个安装包(例如 MSI)。

Command docker run is comparable to running an installer package with the goal of installing an app.命令docker run类似于以安装应用程序为目标运行安装程序包。 So, using same analogy, running an MSI installs an app.因此,使用相同的类比,运行 MSI 会安装应用程序。

Container is comparable to installed application.容器类似于已安装的应用程序。 Just like an app, docker container can run or be in stopped state.就像应用程序一样,docker 容器可以运行或处于停止状态。 This depends on the environment, which I referred to as "hosting" above.这取决于环境,我在上面将其称为“托管”。

Just like you can build an MSI package on one machine and run it on other machines, you build docker images on one machine (pipeline host, in your case), but you need to host them in environments that support that.就像您可以在一台机器上构建 MSI 包并在其他机器上运行它一样,您可以在一台机器上构建 docker 镜像(在您的情况下是管道主机),但您需要将它们托管在支持它的环境中。

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

相关问题 在 Jenkins Shell 中运行 Docker 命令 - Run Docker commands in Jenkins Shell 在 Jenkins Docker 代理中使用测试容器:容器无法启动,NoRouteToHostException - Using testcontainers in a Jenkins Docker Agent: containers fail to start, NoRouteToHostException 如何从基于 arguments 的 shell 脚本启动 Docker 容器 - How to start Docker containers from shell script based on arguments docker命令在jenkins shell步骤中失败 - docker commands failing in jenkins shell step 如何使用 shell 脚本监控 docker 容器资源使用情况 - how to monitor docker containers resource usage using shell script 在 Bitnami 的 Jenkins 上在 Jenkins shell ubuntu 中运行 Docker 命令 - On Bitnami's Jenkins Run Docker Commands in Jenkins shell ubuntu 如何在Docker for mac中自动启动docker容器? - How to auto start docker containers in Docker for mac? Docker 容器启动和停止时在主机上运行命令 - Run commands on host when Docker containers start and stop 如何使用设备映射器将Docker容器移动到另一台机器上而不使用docker命令 - How to move docker containers using device mapper to another machine without using docker commands docker 容器上的 Ansible 命令? - Ansible commands on docker containers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM