Dockerfile Multiple Inheritance with nested builds #25531
Labels
area/builder
kind/feature
Functionality or other elements that the project doesn't currently have. Features are new and shiny
I would like to initiate a discussion about a different approach of solving the same issue that many people want to fix with those Mixins or Include proposals.
Here is a list of those referred discussions:
#24445
#3378
#735
My two cents. The approach of using nested builds would be actually pretty simple. Inside the Dockerfile there would be a new command for running another build (from now, I'll refer to it as the subbuild), and that subbuild would be as isolated as any other build, it will be in fact a build running externally in its own build context. Additionally, you declare which paths of the subbuild will be copied into the parent build.
Example:
In the example you can see that we are taking nginx:1.11.1 as base image, and in the second line we are: 1. building the Dockerfile named "Dockerfile.node-artifact" located in the host to create a subbuild image, and 2. copying the folder "/dist" of the subbuild image to the location "/usr/share/nginx/html" of the resulting parent intermediate image
Also, because of the existing --build-arg feature, there is a very nice opportunity to:
Change the subbuild Dockerfile depending on an ARG/ENV variable.
Example:
Influence the subbuild from the parent build by passing arguments, so the subbuild can be generic if that makes sense for a given use case.
Example:
Another extra could be using already existing images instead of Dockerfiles.
Example:
The main advantage of this approach vs include-like solutions is that the builds are still isolated. In one hand, the subbuilds keep their own cache, and can be built and tested without the parent build. And in the other, the input/output bounds are explicit and clear from the parent build perspective, and wouldn't produce conflicts between images.
Other things that needs discussion and I didn't mention yet about this proposal:
I think implementation of this feature wouldn't be that complicated, as this would translate into another docker build, docker cp in the host system, followed by a COPY within the Dockerfile.
The text was updated successfully, but these errors were encountered: