gcloud docker push results in "denied: Token exchange failed for project 'gcp-project-id-example'."

After creating and downloading the keyfile.json I export GOOGLE_APPLICATION_CREDENTIALS to the location of the file

export GOOGLE_APPLICATION_CREDENTIALS=/var/lib/jenkins/gcp/keyfile.json

this is what I did that worked for me:

docker login -u _json_key -p "`cat ${GOOGLE_APPLICATION_CREDENTIALS}`" https://gcr.io

hope it helps


When you run gcloud auth configure-docker as a normal user it saves a configuration file in ~/.docker/config.json - and this file is not used afterwards when running via the root user or sudo...

So an easy work around is sudo -u $USER docker push gcr.io/example/example:latest