How does one get the size of a Docker image before they pull it to their machine?
If you really look into the docker code for pull operation, I think your answer is there. If the image of the container is not cached, then during pulling of the image, docker first collects the information about the image from the registry like number of layers, size of each layers etc. etc.
I would refer to read this file.
https://github.com/moxiegirl/docker/blob/master/distribution/xfer/download.go