Same base image for multiple unique builds

Hi,

I need to do two unique docker build operations (i.e. a separate and unique Dockerfile for each) off of the same base image.

The base image is hosted and I need to end up with two copies of this same image that are separate and unique from each other so that I can apply the docker build command to them individually, each with a unique Dockerfile so that I can layer a different set of tools and code into each image.

I tried using docker tag, but when I did that, it created a “copy” of my image, but it had the same ID string as the original, so it looks like a pointer to the original and not a physical copy.

Is it possible to do this, and if so, what is the correct approach?

Using docker engine v20.10.21 and Docker Desktop 4.14.1 (91661) on Windows 10.

Thank you.

Do you really need an actual, independent copy? What would you achieve? I have read your explanation, but I don’t understand it. Do you know that an image is just a template and you can use it as a base image for as many new images as you want? You don’t need a copy. The original image will never change.

Thanks for the reply. I am very new to Docker, so it is likely my problem is only that I don’t understand what I’m doing! While I do understand that the base image is a template and immutable, what I’m not sure about is what happens after I have downloaded it (and can see it in Docker Desktop in the Images page) and then applied a docker build command to it to add some layers. Then, I need to use the same base image and apply another docker build to it that adds different layers, and I need both of those builds to be kept separate from each other so that I can spin up two unique containers, one based off of each of the two builds. I’m concerned that my second build will overwrite the first build. Hopefully I made my use case clearer this time. I’m just looking for a way to achieve this result, and when done I’m expecting to see (perhaps incorrectly) two images in my Docker Desktop, each with a unique name and ID, that I can then apply separate docker run commands to in order to spin up two unique containers. Thanks again for your help.

This is the key. Unless you do something like

FROM originalimagename
# ...
docker build . -t originalimagename

your “original image” will never change and you can refer to its name as many times as you want. Just make sure you give a different name to the new image.

FROM originalimagename
# ...
docker build . -t customimagename

Thank you very much. That is what I needed to know.