拉和运行使用Jenkinsdocker插件的docker图像

我试图找出如何从Jenkins里面的docker hub中拖出一个Docker镜像。 docker插件似乎是要走的路。 然而,尽pipe我可以在公共领域find大量的信息,并且为了构build图像并将它们推送到registry而堆栈溢出,但我正在努力寻找任何用于拉取图像和旋转容器的东西。 我可以find很多像这样的东西:

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

大概一定有一种拉图像的方法,并使用类似的东西来旋转容器?

使用与pipe道一起使用的插件的基本示例:

 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' } } } }