kaniko
kaniko copied to clipboard
Multi stage build: could not parse reference
Actual behavior Building a dockerfile with multi stage build results in:
INFO[2021-11-16T20:34:47Z] Resolved base name <ecr>/open-source-mirror/dockerhub/gradle:6.8-jdk11 to builder
DEBU[2021-11-16T20:34:47Z] Built stage name to index map: map[builder:0]
DEBU[2021-11-16T20:34:47Z] Found extra base image stage 0
INFO[2021-11-16T20:34:47Z] Retrieving image manifest 0
error building image: could not parse reference: 0
Expected behavior Image gets built
To Reproduce
/kaniko/executor --cache=true --cache-copy-layers=false --dockerfile=Dockerfile --verbosity debug --log-timestamp=true --snapshotMode=redo --skip-unused-stages=true
Removed cache destination for privacy reasons.
Additional Information Dockerfile
### Stage: Builder
FROM <repo>/open-source-mirror/dockerhub/gradle:6.8-jdk11 as builder
WORKDIR /workspace
COPY . /workspace
RUN gradle build
FROM <repo>/base:tag AS runner
WORKDIR /home/app
COPY . /home/app
COPY --from=builder /workspace/build/libs/*-all.jar /home/app/app.jar
EXPOSE 8080
CMD ["/home/app/run-server.sh", "/home/app/run"]
Kaniko version: gcr.io/kaniko-project/executor:debug
Description | Yes/No |
---|---|
Please check if this a new feature you are proposing |
|
Please check if the build works in docker but not in kaniko |
|
Please check if this error is seen when you use --cache flag |
|
Please check if your dockerfile is a multistage dockerfile |
|
Digging some more, it seems like this might be the culprit due to how long our repo name is and how many /
it contains
I'm getting a similar error. Was there a resolution to this?
Same issue on our side. We are trying to build an image from a private gitlab registry (with a long name) and it fails with this error:
error building image: could not parse reference: 0
Just got randomly stuck on this today as well. In my case - not a long image name as I am using node:18-buster
- but same behaviour and clearing the Gitlab Runner cache did nothing to solve it. Seems like it may be something else and this is some sort of catch all error. But at the moment I cannot for the life of me figure out what. Would be nice to figure out how to bubble a proper error here.
INFO[0007] Resolved base name node:18-buster to builder
INFO[0007] Using dockerignore file: <scrubbed>
INFO[0007] Retrieving image manifest 0
error building image: could not parse reference: 0
Gah, finally figured out that my specific case was a Dockerfile error.
ARG build_config=development
RUN echo "Running ${build_config} build..." \
&& $(npm bin)/ng build --configuration ${build_config} \
&& $(npm bin)/ng run angular:server:${build_config} #\
# && $(npm bin)/ng run angular:prerender:${build_config}
I had commented out the prerender line due to a bug, and did an end-of-line comment in the docker file for the slash #\
- this doesn't work with RUN
in kaniko it seems, and this causes the parse issue. But no feedback made working this out take forever.
Working again with:
ARG build_config=development
RUN echo "Running ${build_config} build..." \
&& $(npm bin)/ng build --configuration ${build_config} \
&& $(npm bin)/ng run angular:server:${build_config}
# && $(npm bin)/ng run angular:prerender:${build_config}
It does appear my suspicion about this being an message catching multiple possible problems was correct. In lieu of better feedback - a doc pointing people in the right direction would at least prevent them from troubleshooting their CI jobs, caching and kaniko setup instead of looking at their Dockerfile
more closely.
I'm also having a similar issue with simple dockerFile. The similarity that i see is the image name which is long and with multiple '/' in the base name. With shorter image names it works.
kaniko-build --context ${CI_PROJECT_DIR} --build-arg API_IMAGE=${API_IMAGE} --dockerfile ${CI_PROJECT_DIR}/cicd/docker/nginx/Dockerfile --destination ${NGINX_IMAGE}
INFO[0000] Resolved base name ci-dcr.company.com/team/product/service-api:version to api
INFO[0000] Using dockerignore file: /builds/<scrubbed>/.dockerignore
INFO[0000] Retrieving image manifest 1
error building image: could not parse reference: 1
FROM nginx:alpine
WORKDIR /usr/share/nginx/html/
COPY ./cicd/docker/nginx/default.conf /etc/nginx/conf.d/
RUN mkdir /usr/src/nginx/html/api
ARG API_IMAGE
FROM $API_IMAGE as API
COPY --from=API /var/www/service-api/ /usr/src/nginx/html/api/
I have some results out of my investigation. There were actually 2 issues in combination:
- the wrong order of multi stage image. It should have been
ARG API_IMAGE
FROM $API_IMAGE as API
FROM nginx:alpine
WORKDIR /usr/share/nginx/html/
COPY ./cicd/docker/nginx/default.conf /etc/nginx/conf.d/
RUN mkdir /usr/src/nginx/html/api
COPY --from=API /var/www/service-api/ /usr/src/nginx/html/api/
- I was passing
--skip-unused-stages
config to the kaniko-build command. It seems like even with correct order, used with this config, it was failing for the variable image name passed as argument. Removing it worked.