Search code examples
dockerdocker-registry

Docker registry space if pushing two images from same docker file


What happens on docker registry server space side when an image is created from same docker file. So, for example in case below, if I push an image with tag 1.0 and then create another image with same docker file and push that with tag 1.1. Is it going to take any additional space on docker registry?

docker build . -t myRegistry.com/myImage:1.0
docker push myRegistry.com/myImage:1.0

docker build . -t myRegistry.com/myImage:1.1
docker push myRegistry.com/myImage:1.1

docker build . -t myRegistry.com/myImage:1.2
docker push myRegistry.com/myImage:1.2

docker build . -t myRegistry.com/myImage:1.3
docker push myRegistry.com/myImage:1.3

Solution

  • In your sample case, the container registry will use the same image, which is calculated by the image's sha256 value (also known as the IMAGE ID) -- the tag is simply alias to that unique image.

    It's a one-to-many relationship, i.e., you can have many tags point to the same image. You can use docker images --no-trunc to see the full value of the IMAGE ID. (Note this is useful if you have consistency issues using common tags like "latest" or "develop" since you can't be sure which image it actually is unless you use the sha256 value.)

    For builds on different machines/environments, using the same Dockerfile with the same files may result in the same hash, but it depends on many variables like how dynamic your dependencies are, if timestamps have changed, etc.

    As @Henry mentioned, this further applies (largely behind the scenes) to individual layers of an image:

    Docker images have intermediate layers that increase reusability, decrease disk usage, and speed up docker build by allowing each step to be cached. These intermediate layers are not shown by default.

    see docs

    Btw, to see a container's sha256 value to see which image it came from, you can inspect it, e.g., docker inspect --format='{{index .RepoDigests 0}}' mongo:3.4-jessie