I am trying to push a Docker image into my container registry on Google Cloud platform. I am able to build my image successfully on my local machine. I tried the following command:
sudo docker push eu.gcr.io/$PROJECT_ID/$CONTAINER_NAME
I get a permission denied error:
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 tried following the steps in the provided link, specifically the gcloud credential helper instructions. I also tried gcloud auth configure-docker
and gcloud auth login
, all to no avail. Regarding IAM permissions my personal email is listed as Owner and Storage Admin role. I also have manually set up a service account with Owner and Storage admin roles. My $GOOGLE_APPLICATION_CREDENTIALS
environment variable points to a json file extracted from this manually created service account. gcloud auth configure-docker
provides the following output:
WARNING: Your config file at [/home/awa5114/.docker/config.json] contains these credential helper entries:
{
"credHelpers": {
"gcr.io": "gcloud",
"us.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"asia.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud"
}
}
Adding credentials for all GCR repositories.
WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
gcloud credential helpers already registered correctly.
At this point, I don't understand why I am getting denied permission to push this image into the container registry. What can I try next?
I finally got it to work. I did two things:
sudo
before the docker push
command....