Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple auths/ logins for same docker registry

Tags:

docker

gitlab

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?

like image 269
gucki Avatar asked May 04 '18 15:05

gucki


People also ask

Can you login to multiple Docker registries?

Even with vanilla Docker you cannot login to multiple registries at the same time if they share the same domain.

Where are Docker registry credentials stored?

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%/.

Which options configures the Docker daemon to connect to a registry?

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.


1 Answers

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.

like image 131
segalaj Avatar answered Sep 24 '22 03:09

segalaj