One additional question, with this solution, do I need to add $REGISTRY for the public images also or just my private ones? Because I want to avoid the pull rate limit from DockerHub, so I need the public images fetched from DockerHub to be done in an authenticated manner.
You would use a $REGISTRY prefix if you want to use a pull through cache to manage image pulls from docker.io. Gitlab’ dependecy proxy contains the docs for this.
Otherwise, if you have a DOCKER_AUTH_CONFIG or explicit docker login in your job, you can just use the plain image names that you find on Docker Hub.
Thanks for pointing out, I am familiar with the Dependency proxy solution though.
On the second point, the documentation says that if I put DOCKER_AUTH_CONFIG in CI/CD variables, then on the image: and the scripts: I need to add the registry in front. Which means I have to change my .gitlab-ci.yml file.
I wanted to avoid changing the .gitlab-ci.yml.
Are you saying that the documentation is not necessarily true? That if I put DOCKER_AUTH_CONFIG in CI/CD variables, both for image: and scripts: I do not need to add the $REGISTRY in front?
I suspect the documentation is conflating some ideas like authenticated registries are usually not docker.io.
The core idea is, the registry you provide auth for in your .docker/config.json / DOCKER_AUTH_CONFIG must match the registry implied by the image repository.
Docker, automatically, when given simple image names (without a domain) will prepend registry2.docker.io/library/ onto the image. (library is implicitly prepended for any repositories that don’t contain a slash. So alpine is actually library/alpine).
And this then matches the entry generated when you docker login without a repository.
Because this is all done by docker you don’t need $REGISTRY as a image prefix.