Search code examples
dockergoogle-cloud-platformpermissionsgoogle-container-registry

Google Container Registry permission


I am trying to push docker image to GCP, but i am still getting this 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 follow this https://cloud.google.com/container-registry/docs/quickstart step by step and everything works fine until docker push

It's clear GCP project

I've already tried:

  1. use gcloud as a Docker credential helper: gcloud auth configure-docker
  2. reinstall Cloud SDK and gcloud init
  3. add Storage Admin role to my account

What I am doing wrong?

Thanks for any suggestions


Solution

  • If it can help those in the same situation as me:

    • Docker 19.03
    • Google cloud SDK 288.0.0

    Important: My user is not in a docker user group. I then have to prepend sudo before any docker command

    When gcloud and docker are not using the same config.json

    When I use gcloud credential helper:

    gcloud auth configure-docker
    

    it updates the JSON config file in my $HOME: [/home/{username}/.docker/config.json]. However, when logging out and login again from Docker CLI,

    sudo docker login
    

    The warning shows a different path, which makes sense as I sudo-ed:

    WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
    

    sudo everywhere

    To fix it, I did the following steps:

    # Clear everything
    sudo docker logout
    sudo rm /root/.docker/config.json
    rm /home/{username}/.docker/config.json
    
    # Re-login
    sudo docker login
    sudo gcloud auth login --no-launch-browser # --no-launch-browser is optional
    
    # Check both Docker CLI and gcloud credential helper are here
    sudo vim /root/.docker/config.json
    
    # Just in case
    sudo gcloud config set project {PROJECT_ID}
    

    I can now push my Docker images to both GCR and Docker hub