我试图找出如何从Jenkins里面的docker hub中拉出并运行一个泊坞窗图像。 docker插件似乎是要走的路。然而,尽管我可以在公共领域找到大量信息并且堆栈溢出用于构建图像并将它们推送到注册表,但是我很难找到任何用于拉动图像和旋转容器的东西。我可以找到很多看起来像这样的东西:
newImage = docker.build(appNameWithBranch)
docker.withRegistry("https://${registryAddress}", ''){
newImage.push("${variables.version}")
}
据推测,必须有一种方法来拉动图像并使用类似的东西来旋转容器?
答案 0 :(得分:2)
使用管道附带的插件的基本示例:
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'
}
}
}
}