Carpetfizz
Carpetfizz

Reputation: 9169

Set up two multi-stage builds without repeating yourself

My application is built using a multi-stage build in the following way.

Dockerfile 1

FROM debian:stretch as prebuilder
# Define the prebuilder
FROM prebuilder as build-stage
# Build app 1
FROM build-stage as run-stage
# Copy app 1 from build-stage and setup runtime environment

Dockerfile 2

FROM debian:stretch as prebuilder
# Define the prebuilder
FROM prebuilder as build-stage
# Build app 2
FROM build-stage as run-stage
# Copy app 2 from build-stage and setup runtime environment

The problem is that the prebuilder and run-stage are identical in app 1 and app 2 (except for the actual app files that are copied over from the build-stage to the run-stage. So I'm repeating myself unnecessarily in both Dockerfiles.

Are there any built-in constructs in Docker multi-stage builds to start a build stage using a build stage from another image (even though it's not the final stage)?

Thanks!

Upvotes: 0

Views: 329

Answers (1)

Amir
Amir

Reputation: 1274

You can use the official Docker registry for local image registry platform.

This is how you can go about it:

  1. Build your redundant/shared parent image
  2. Push it to your docker registry(if you have any scopes or environment you can push it as per your scope/environment)
  3. Use it in the other docker files as a base image

Upvotes: 1

Related Questions