如何解决“无法从 docker 中检索 .Id"使用 Jenkins 管道构建 Docker 映像时 [英] How to resolve "Cannot retrieve .Id from docker" when building Docker image using Jenkins pipeline
问题描述
我正在使用 Jenkins 管道来构建 Dockerfile.
I am using a Jenkins pipeline to build a Dockerfile.
dockerfile 成功完成所有步骤,并创建了 docker 镜像.
The dockerfile successfully goes through all steps, and creates the docker image.
如图:
Step 16/19 : FROM base AS final
---> <id>
Step 17/19 : WORKDIR /app
---> Using cache
---> <id>
Step 18/19 : COPY --from=publish /app .
---> Using cache
---> <id>
Step 19/19 : ENTRYPOINT ["", "myapp.dll"]
---> Using cache
---> <id>
Successfully built cb3y81938e88
Successfully tagged myapp:latest
但是,在此之后,shell 失败并出现以下错误:
However, after this, the shell Fails with the following error:
java.io.IOException: Cannot retrieve .Id from 'docker inspect base AS final'
尽管 docker 镜像构建成功,为什么它会抛出这个错误?当我在本地机器上执行此操作时,命令在成功标记 myapp:latest"时退出
Why does it throw this error despite the docker image successfully built? When I execute this on my local machine, the command exits on "Successfully tagged myapp:latest"
我的 docker 版本是 18.03.1-ce.
My docker version is 18.03.1-ce.
对于这个问题的任何帮助将不胜感激!
Any help on this issue would be greatly appreciated!
推荐答案
那个Jenkins插件好像有bug.
It seems that there is a bug in that Jenkins plugin.
您可以尝试删除多阶段构建名称(AS final
",因为您不需要它):
You can try removing multi stage build name ("AS final
" as you don't need it):
FROM base
(....)
但如果您确实需要引用之前构建的图像(多阶段),则可以使用 --copy-from 0
(对应的 0,1,2,而不是别名)
But if you really need to reference a previous built image (multi stage), a workaround can be using --copy-from 0
(0,1,2 as it corresponds, instead of the alias name)
Jenkins 中的相关问题
Related issues in Jenkins
- https://issues.jenkins-ci.org/browse/JENKINS-44789
- https://issues.jenkins-ci.org/browse/JENKINS-44609
- https://issues.jenkins-ci.org/browse/JENKINS-31507
编辑
在此处记录 OP 找到的解决方案:
Documenting here the solution found by the OP:
我没有使用 Jenkinsfile 管道文件,而是在 Jenkins 作业中执行一个 Shell 来执行 Docker 构建命令,从而实现了这项工作.(docker build -t latest-build .)
I got this working by not using the Jenkinsfile pipeline file, but instead executing a Shell within the Jenkins job to execute the Docker build command. (docker build -t latest-build .)
这篇关于如何解决“无法从 docker 中检索 .Id"使用 Jenkins 管道构建 Docker 映像时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!