Use short lived token to push docker image to GCP

12/18/2018

I have a service account and key json file contents in my process. Trying to spawn "docker gcr.io/my-project/my-image" to upload images to container registry.

I tried docker login -u _json_key -p "$(cat keyfile.json)" https://[HOSTNAME] from Advanced Authentication tutorial, which returns success during login, but still docker push returns error:

You do not currently have an active account selected.
Please run:

  $ gcloud auth login

Ideally, I would like to trigger docker push without configuring gcloud SDK. Also would not want to store key json contents to a file. I'd like to keep it in process memory.

-- rubenhak
authentication
docker
google-cloud-platform
google-kubernetes-engine
json

1 Answer

12/18/2018

The correct command to run for docker clients 18.03 and newer is gcloud auth configure-docker.

If you read the fine print for your command docker login -u _json_key -p "$(cat keyfile.json)" https://[HOSTNAME] it mentions for older Docker clients e.g. several years old. This is not the correct command to run today.

With the constant improvements, new features, Kubernetes, etc. you do not want to be running old commands or configurations.

gcloud auth configure-docker

-- John Hanley
Source: StackOverflow