I am using a Jenkins pipeline to build a Dockerfile.
The dockerfile successfully goes through all steps, and creates the docker image.
As shown:
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
However, after this, the shell Fails with the following error:
java.io.IOException: Cannot retrieve .Id from 'docker inspect base AS final'
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"
My docker version is 18.03.1-ce.
Any help on this issue would be greatly appreciated!
I'm getting this problem because I'm using
--target=<foo>
to build my image only up to a certain point.So my Dockerfile looks like this
And my build with
docker.build(<tag>, "--target=BUILD .")
fails with:This is because Jenkins is trying to inspect the second
FROM openjdk:8
in the Dockerfile, and because that target didn't run Docker didn't pull down that image and it's unavailable todocker inspect
I've got a bunch of workarounds available to me:
docker pull openjdk:8
before building--target=BUILD
from mydocker.build
command and let it build the whole thing (not too big a deal for me as the build is the most expensive part)docker.build
and justsh "docker build --target=BUILD .
At the moment I'm not sure which one I'll go with
None of the above ideas works for my case, and I finally got it work as below pipeline without chaning anything on Dockerfile:
It seems that there is a bug in that Jenkins plugin.
You can try removing multi stage build name ("
AS final
" as you don't need it):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)Related issues in Jenkins
Edit
Documenting here the solution found by the OP:
I ran into this same problem with Docker 18.09, but I wasn't using a multi stage build. In my case, I was getting:
The first step in my Dockerfile was:
I was able to fix the problem with
docker pull centos:7
; after that, the Jenkins build was able to complete successfully.