I have a Dockerfile that produces an image as a result of a multi-stage build. One of the steps produces a file (an sql migration script) that I would like to export and store somewhere outside of the build process, while I still want the build to produce the final image.
I was looking at the approach explained here How to copy files from host to Docker container?. It works well, but there is a couple of problems with it:
- It either produces the image or output the files.
- It only exports the files from the last stage. To limit the number of exported files, I can to use the scratch image, but that is not the final image I want to produce.
FROM scratch AS export
COPY --from=build /script.sql /
If I just copy the sql script into the finally produced (production) image, it will output all the build-produced files. And I also don't really want the script to be in the final image as it has no purpose there.
Is there any way how to do it? Feels silly to run two separated Dockerfiles to do the same build, one to generate the script and another to produce the image.