docker won't let push image to google cloud despite logged in as owner and authenticated as credential helper

733 Views Asked by At

as you can see I tagged my most recent image to belong to google cloud registry:

$ docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
gcr.io/chess-king-council/council-kings   latest              e82b2f44af48        4 hours ago         1.05GB
<none>                                    <none>              63a6c4d89d29        4 hours ago         1.05GB
<none>                                    <none>              b4637ec645fa        4 hours ago         1.05GB
<none>                                    <none>              466bb4fd8026        4 hours ago         332MB
ubuntu                                    20.04               4e2eef94cd6b        2 weeks ago         73.9MB
ubuntu                                    latest              4e2eef94cd6b        2 weeks ago         73.9MB
python                                    3.8.2               4f7cd4269fa9        4 months ago        934MB
node                                      13.12.0-alpine      483343d6c5f5        5 months ago        114MB

when I run the command:

docker push gcr.io/chess-king-council/council-kings

It gives the message:

unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication

I followed the steps at the link it gave to authenticate as a Docker credential helper, but nothing changed. Also, I am logged in as the owner of the project. Why won't google cloud let me push this Docker image? Am I missing something obvious?

2

There are 2 best solutions below

0
MaryM On

This error can happen when the SDK is missing from the PATH and not necessarily a permissions issue. Check that in your ~/.bash_profile you have the location to the SDK in the $PATH as mentioned here on step #5.

example:

export PATH="/usr/local/yourfolder/google-cloud-sdk/latest/google-cloud-sdk/bin:$PATH"

0
Jendoliver On

I have lost many hours with this problem. As you, I was sure that I followed all the steps in the gcloud documentation. I was also able to run docker without root because I did the proper setup after installing it. Checked the permissions in the gcloud project and image bucket, all correct.

In the end it was the most stupid thing: I had installed docker through snap instead of apt, and apparently the snap installation stores the config.json file in a different path than $HOME/.docker/config.json. I noticed this out of luck while simply running docker:

$ docker

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
--->   --config string      Location of client config files (default "<PATH_TO_DOCKER_FOLDER_WITHIN_SNAP>")

The default path was not $HOME/.docker, but one within the snap installation. So when I was running gcloud auth configure-docker, the modified config was the one in $HOME/.docker/config.json, but when trying to push the image docker was loading the config stored within the snap path, that didn't have gcloud configured as a credential helper.

The solution after realizing this was straight-forward: removing the snap installation and using apt like I should have done since the beginning fixed it. Hopefully this saves someone some pain...