user32882
user32882

Reputation: 5907

Unable to push Docker image into GCP container registry [permission error]

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?

Upvotes: 0

Views: 1354

Answers (3)

user20934433
user20934433

Reputation: 1

running docker push without "sudo" resolved the same issue for me,

Running Docker commands without sudo requires that your user is added to the docker group. By default, Docker commands need root privileges, which is why they typically require sudo. Adding your user to the docker group grants the necessary permissions to run Docker commands without sudo

Upvotes: 0

siddhi chavan
siddhi chavan

Reputation: 1

I resolved this error by restarting docker engine

Upvotes: 0

user32882
user32882

Reputation: 5907

I finally got it to work. I did two things:

  • completely reinstall docker using the official instructions from their website.
  • do not use sudo before the docker push command....

Upvotes: 1

Related Questions