I find myself often repeating dockerfile content. For example for a typical spring-boot application, this would be as follows:
FROM $BUILD_IMAGE as build
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src src
RUN mvn package
RUN java -Djarmode=layertools -jar target/application.jar extract
FROM $RUNTIME_IMAGE
COPY --from=build /application/dependencies/ ./
COPY --from=build /application/spring-boot-loader/ ./
COPY --from=build /application/snapshot-dependencies/ ./
COPY --from=build /application/application/ ./
EXPOSE 8081
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
Here only 3 things are dynamic based on the project that executes the dockerfile: pom.xml, src, EXPOSE <port>. Everything else is always the same.
Question: is it possible to create some kind of "template", so that I can "feed" the template with those 3 dynamic files or folders?
I would not want to copy the dockerfile into all of my projects 1:1. I would prefer if I could use the dockerfile as a base definition, and reference it from all of my spring-boot projects.