save docker registry token for repo
Before starting to download an image there are two or three steps:
- Fetch docker image manifest
- Fetch a single docker image manifest if the first request returned a manifest list
- Fetch image configuration object
These are simple requests from docker registry. When the registry requires authorization, we make another request to get a token. After that, we make our first request again, using this token (see doc). Therefore, for above 3 steps, we make a total of 9 requests.
Save the token that we obtained in the first step to also use in the succeeding steps. By doing so, the number of requests sent before starting to download the image will be reduced by 4.
Furthermore, after starting to download the image, for the case where we download the image layer by layer from origin, use this token each time we make a request to download a layer.
In conclusion, this way, say
n is the number of layers of the image, we will be able to reduce the total number of requests by
n x 2 + 4.