[英]Jenkins always pull docker image from a declarative pipeline agent definition
I have a working Jenkins pipeline defined with agent {any}
.我有一个使用agent {any}
定义的工作 Jenkins 管道。
But I want to try running the tests on a docker image.但我想尝试在 docker 镜像上运行测试。 According to documentation I can do that the following way:根据文档,我可以通过以下方式做到这一点:
pipeline {
agent {
docker { image 'centos/python-27-centos7:latest' }
}
stages {
...
}
}
The problem is that my instance of Jenkins is offline and with this configuration it will try to docker pull
the image when running the project.问题是我的 Jenkins 实例处于离线状态,使用此配置,它会在运行项目时尝试docker pull
图像。
However I have the centos/python-27 image loaded in the docker (visible with docker images
and it can be run with docker run -i -t centos/python-27-centos7 /bin/bash
但是,我在 docker 中加载了 centos/python-27 图像(通过docker images
可见,它可以通过docker run -i -t centos/python-27-centos7 /bin/bash
Is there any way I can configure the agent in Jenkins so it doesn't try to pull
the image from Docker Hub?有什么方法可以在 Jenkins 中配置代理,使其不会尝试从 Docker Hub 中pull
图像?
The Docker agent has an alwaysPull
flag you can set to false
or true
: Docker 代理有一个alwaysPull
标志,您可以将其设置为false
或true
:
agent {
docker {
alwaysPull false
image 'foo/bar'
}
}
Jenkins has a Pipeline Syntax Generator that can help in these cases. Jenkins 有一个 Pipeline Syntax Generator 可以在这些情况下提供帮助。 In the Job menu on the left side, there is an icon for "Pipeline Syntax".在左侧的 Job 菜单中,有一个“Pipeline Syntax”图标。
There you can see some settings to help you generate your pipeline directives.在那里您可以看到一些设置来帮助您生成管道指令。
You could try to use a dockerfile agent.您可以尝试使用 dockerfile 代理。 If everything you need to build the image is local, then you won't have to be online.如果构建映像所需的一切都是本地的,那么您就不必在线了。
pipeline {
agent {
dockerfile {
filename "someOtherDockerfile"
label "docker-nodes"
args "-v /tmp:/tmp"
}
}
stages {
...
}
Your other option is possibly setting up a private docker registry.您的另一个选择可能是设置私有 docker 注册表。 https://docs.docker.com/registry/deploying/ https://docs.docker.com/registry/deploying/
You should us siblings instead of nested container images.你应该我们兄弟姐妹而不是嵌套的容器图像。 ie Try to mount the volume of docker daemon sockets to the Jenkins container via -v /var/run/docker.sock:/var/run/docker.sock
.即尝试通过-v /var/run/docker.sock:/var/run/docker.sock
将 docker 守护进程套接字的卷挂载到 Jenkins 容器。 This way, you will get access to the images available on your host system.这样,您就可以访问主机系统上可用的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.