Open Tzvetelin88 opened 1 year ago
I had the same issue before, the reason is that the final stage doesn't use any output from the update stage, and docker build uses a dependency tree to determine which stages are needed by the final stage and skips all unnecessary stages.
I solved the issue by add a dummy text file in the "unnecessary stage" and then copy the dummy file from the intermediate stage to the final stage.
FROM internal.repo/node:18.13.0 as build
....
FROM internal.repo/debian:latest as update
COPY --from=build /usr/app /usr/app
# execute other commands
RUN echo "Placeholder" > /tmp/placeholder.txt
...
FROM internal.repo/debian:latest as final
COPY --from=build /usr/app /usr/app
COPY --from=update /tmp/placeholder.txt .
....
Hope this helps.
Expected behavior
Build all stages with the same "--from="
Actual behavior
Only last stage is builded.
Information
Output of
/Applications/Docker.app/Contents/MacOS/com.docker.diagnose check
Steps to reproduce the behavior
A reproducible case, Dockerfiles FTW.
Only final stage is executed, update is skipped. I read that this is normal behaviour to BuildKit, but is there a best practise way to do it?
I have tried with:
and it worked, but it doesn't seem right to skip Docker Build Kit, as there are a lot of optimisations.
Do you know a way to perform the same "--from=" without skipping BuildKit?
I have tried to give a new FROM with new alias, but it doesn't work: