Does Docker Store Base Images Separately in Built Images?

0
0
Asked By CuriousCat123 On

Hey everyone! I've got a bit of a specific question about Docker. From what I understand, Docker includes the base image when it builds a new image. For example, if I have an image called 'test' that was built from the 'alpine' base image, it looks like this:

REPOSITORY TAG IMAGE ID CREATED SIZE
test latest 84ec88cef292 4 seconds ago 19.1MB
alpine latest 4bcff63911fc 8 weeks ago 12.8MB

In this scenario, I get why Docker includes the base image in the built image, but is there a way to keep it stored separately, whether on a remote repository like Docker Hub or locally? I haven't come across any clear info on this.

I think it would be better if the base image was kept separate, considering Docker utilizes layers. For instance, it could work like this:

alpine:3.21.1 -> my_image:sha_commit
-> other_image:v1.2.3

In this way, both 'my_image' and 'other_image' would only contain the changed files in their layers. Any insights or documentation you could share would be much appreciated! Thanks!

3 Answers

Answered By DockerDude92 On

Just a heads up, seeing those sizes like 19.1MB and 12.8MB might make you think they're storing both separately, but that's not the case. Docker doesn't really include the base image in the built one; it efficiently uses layers.

InquisitiveMind45 -

Thanks for the clarification! I think I may have misunderstood the documentation.

Answered By LayerLover07 On

Docker keeps only one copy of each layer, so it's actually more efficient than what you're suggesting. It already works in a way that uses layers to optimize storage, which I think is pretty cool!

Answered By QuestionAsker2000 On

From what I know, your solution is already implemented in how Docker operates. What made you think otherwise?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.