fatdragon
fatdragon

Reputation: 2299

Dockerfiles sharing the same instructions but built from a different image

What would be the best practice when I need to create multiple docker images that share the same instructions EXCEPT the FROM image?

For example, I want to build 3 different images - a Java stack, a Python stack, and a Rust stack. So I have 3 Dockerfile's each referencing a different FROM image. Then, in each of these Dockerfile, I have a long list of instructions that are exactly the same. I would rather not duplicate the instructions.

Upvotes: 0

Views: 114

Answers (1)

ClumsyPuffin
ClumsyPuffin

Reputation: 4059

You can try passing image name as arguments if only image name is changing

Dockerfile:

ARG img
FROM $img
RUN echo “Building $img”

Then run build command on terminal:

sudo docker build . --build-arg img=busybox

Upvotes: 2

Related Questions