Reputation: 1547
I have a 2 node swarm cluster configured as follows
I have configured Google Container Registry to push and pull images
In the host/local machine where docker swarm configured I can easily login into the google container registry with following command and push/pull images
$ gcloud auth print-access-token | sudo docker login -u oauth2accesstoken --password-stdin https://gcr.io
WARNING: Could not setup log file in /home/arush/.config/gcloud/logs, (PermissionError: [Errno 13] Permission denied: '/home/arush/.config/gcloud/logs/2021.03.09/15.17.13.106143.log')
WARNING! Your password will be stored unencrypted in /home/arush/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
To login I am using Access token method as mentioned here
Now If I try to create service inside swarm on manager node with following command I get message like image not found
$ docker service create --name app1 --with-registry-auth -p 5003:5000 app1
How can I login in google container registry from within the swarm cluster pull images and create services
Upvotes: 0
Views: 1001
Reputation: 2487
I can see you are trying to create a service inside your Swarm cluster and you want to pull your images from Google Container Registry.
Please follow the next steps:
$ docker login -u oauth2accesstoken --password-stdin https://HOSTNAME
or
$ docker login -u _json_key -p "$(cat keyfile.json)" https://HOSTNAME
where HOSTNAME is gcr.io, us.gcr.io, eu.gcr.io, or asia.gcr.io
2) Pull an image from your Container Registry
$ docker pull HOSTNAME/PROJECT-ID/IMAGE:TAG
3) Create a Service from your Swarm node with the pulled image.
$ docker service create --with-registry-auth --name app1 HOSTNAME/PROJECT-ID/IMAGE:TAG
If you are creating the service from a Manager node, please note that the manager node does not share the local images with other nodes automatically.
So you will need to use a Registry accessible from all the nodes of your cluster. But you do not have to use an external common remote repository, you can use a private registry image to create a service on the swarm accessible to all the nodes like this :
docker service create --name registry --publish 5000:5000 registry:2
This way, all the nodes will be able to connect to the registry on “localhost:5000” and pull the image they need to run the containers of your service.
And Then create services from that image :
docker service create --name myservice localhost:5000/myimage
Upvotes: 1