I'm using latest gitlab and the integrated docker registry. For each project I create an individual deploy token. On the host where I want to deploy the images I do docker login https://registry.example.com/project1
, enter the deploy token and get success. Pulling the image just works fine.
On the same host I need to deploy another image from the same registry. So I do docker login https://registry.example.com/project2
, the the deploy token (which is differrent to token 1, because each project has its own deploy tokens) and get success.
However looking in the .docker/config.json
I can see docker just stores the domain, not the full url, and so replaces the old auth token with the new one. So I can only pull image 2 now, but not image 1 anymore.
Is this a bug in docker? How to use more than one auth/ deploy token for the same registry?
Even with vanilla Docker you cannot login to multiple registries at the same time if they share the same domain.
You can log into any public or private repository for which you have credentials. When you log in, the command stores credentials in $HOME/. docker/config. json on Linux or %USERPROFILE%/.
In a typical setup where you run your Registry from the official image, you can specify a configuration variable from the environment by passing -e arguments to your docker run stanza or from within a Dockerfile using the ENV instruction. This variable overrides the /var/lib/registry value to the /somewhere directory.
You can use the --config option of the Docker client to store multiple credentials into different paths:
docker --config ~/.project1 login registry.example.com -u <username> -p <deploy_token> docker --config ~/.project2 login registry.example.com -u <username> -p <deploy_token>
Then you are able to call Docker commands by selecting your credential:
docker --config ~/.project1 pull registry.example.com/project1 docker --config ~/.project2 pull registry.example.com/project2
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With