【问题标题】:pulling and running docker image using Jenkins docker plugin使用 Jenkins docker 插件拉取和运行 docker 镜像
【发布时间】:2017-10-05 03:52:44
【问题描述】:

我正在尝试研究如何从 Jenkins 内部的 docker hub 拉取和运行 docker 映像。码头工人插件似乎是要走的路。然而,尽管我可以在公共域中找到大量信息以及用于构建图像并将它们推送到注册表的堆栈溢出,但我仍在努力寻找任何用于提取图像和旋转容器的东西。我可以找到很多看起来像这样的东西:

newImage = docker.build(appNameWithBranch)
docker.withRegistry("https://${registryAddress}", ''){
    newImage.push("${variables.version}")
}

大概有一种方法可以使用类似的东西来拉取图像和旋转容器?

【问题讨论】:

    标签: docker jenkins


    【解决方案1】:

    使用管道附带的插件的基本示例:

    pipeline {
      agent { label 'docker' }
      stages {
        stage('build') {
          steps {
            script {
              // this pulls an image (groovy:2.4) from docker hub and spins up a container based on it. it exits at the end of the block
              docker.image('groovy:2.4').inside {
                sh 'groovy -v'
                // if you have a file called test.groovy in your jenkins workspace, you can "magically" access it
                // inside the container
                sh 'groovy test.groovy'
              }
            }
    
            // if you want the container to stay up until you shut it down,
            // you can use docker run and include the -d (daemon) flag.
            // here i'm also giving the container the name "nginx-oh-yeah":
            sh 'docker run -d --name nginx-oh-yeah nginx'
          }
        }
      }
    }
    

    【讨论】:

    • 感谢您的回答,但是我认为只要调用 docker.image 就正确。 . . inside 已经完成了容器将不再运行?,我想要的是能够让容器一直悬空直到管道结束。
    • 根据您的更新,如果我阅读正确,容器名称是 nginx ?但是让我感到困惑的是,这似乎没有在任何地方明确设置。
    • nginx 是图像(docs.docker.com/engine/reference/commandline/run)。 :) 再次更新。
    • 我投了你一票,但是由于我的声望不到 15,它确实看起来是公开的盟友。如果你想在博客圈出名,你应该写一篇关于这个的博文,关于它的信息非常零散。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    相关资源
    最近更新 更多