Multistage builds on OpenShift 3.11

Subscribe to our newsletter

While working with OpenShift I did some research on multistage builds and stumbled upon a GitHub issue where people claimed that multistage builds on OpenShift actually worked and wondered why that was the case because OpenShift gets installed with Docker 1.13 and multi-stage builds were only introduced with Docker version 17.05.

Turns out that for Dockerfile based builds OpenShift is using a builder image when multistage configuration is detected. The Image Builder supports Dockerfule multistage unlike the Docker version that is installed with OpenShift. The Image Builder also squashes the images layers whether you like this or not. It is not a configurable option.

As this is undocumented functionality it is also unlikely to get official Red Hat support for OpenShift Enterprise if you need it.

Another officially supported option that OpenShift offers for similar (and more complex) functionality are chained builds. As the build guide states:

"Two builds can be chained together: one that produces the compiled artifact, and a second build that places that artifact in a separate image that runs the artifact."

For instance it is possible to use the S2I (source to image) build strategy to create build artifacts that another build configuration based on a Dockerfile is using.

Get our weekly newsletter

Marketing permission: I give my consent to KUBEMAG to be in touch with me via email using the information I have provided in this form for the purpose of news and updates.