【发布时间】:2021-06-09 12:58:43
【问题描述】:
我正在尝试为我的供应商提供的 special-app 容器找到一种方法:
- 从供应商处拉取 docker 镜像
- 将 docker 映像推送到内部存储库(用于本地副本)
目前对于我从 3rd 方存储库获得的其他 docker 映像,我可以在 Github 中找到它们,它们包含 Dockerfile,然后我在管道中使用它来构建,然后像这样推送到我的个人存储库:
stage('Clone from Git') {
try {
git branch: 'master',
url: 'https://github.com/exampleapp.git'
} catch (Exception ex) {
println("Unable to git clone: ${ex}")
error 'Git Clone failure'
}
}
stage ('Build Docker Image') {
try {
dir('./') {
def customImage =
docker.build("myregistry.com/myimages/exampleapp:${env.BUILD_ID}")
}
} catch (Exception ex) {
error 'Docker Build failure'
}
}
stage ('Push Image to Registry') {
try {
docker.withRegistry('https://myregistry.com', 'mycreds') {
def customImage =
docker.image("myregistry.com/myimages/exampleapp:${env.BUILD_ID}")
customImage.push('latest')
}
} catch (Exception ex) {
println("Unable push image to registry: ${ex}")
error 'Registry Push failure'
}
}
但是对于special-app,供应商基本上只提供了一个yaml文件,然后我用它来创建容器:
docker-compose -p special-app -f vendor-provided.yml up -d
虽然这可以让容器启动并运行,但没有随此方法提供 Dockerfile,因此我无法使用上述相同的方法,用于我确实有 Dockerfile 的其他图像。 在这种情况下我应该怎么做?如果我没有 Dockerfile,如何从供应商处获取 docker 映像并将其推送到我的本地存储库以进行保管?还有其他方法可以在我的管道中实现这一目标吗?
(我们将这些图像的本地副本作为标准流程保留,即使我们没有对其中一些图像进行调整/自定义 - 这就是 special-app 中的情况)。
谢谢 J
【问题讨论】:
标签: docker jenkins dockerfile jenkins-pipeline