Bobcares

How to Set Up gcloud auth configure-docker for Artifact Registry

by | Mar 26, 2025

Learn how to set up gcloud auth configure-docker for Artifact Registry. Our Google Cloud Support team is here to help you with your questions and concerns.

How to Set Up gcloud auth configure-docker for Artifact Registry

How to Set Up gcloud auth configure-docker for Artifact RegistryArtifact Registry by Google Cloud offers a unified platform for storing, managing, and securing packages and container images, ensuring smooth CI/CD integration.

Some of the key features of Artifact Registry include:

  • Store, manage, and secure artifacts efficiently.
  • Compatible with existing CI/CD tools, Cloud Identity and Access Management, and other Google Cloud services.
  • Create multiple regional repositories within a single Google Cloud project.
  • Manage permissions at the project or repository level.

Setting Up Authentication for Artifact Registry

  1. First, run the following command to authenticate with Artifact Registry:

    gcloud beta auth configure-docker us-central1-docker.pkg.dev

  2. Docker requires authentication to interact with the Artifact Registry. So, use the standalone Docker credential helper tool to configure access without `gcloud`:


    VERSION=2.0.0
    OS=linux # Use "darwin" for macOS, "windows" for Windows.
    ARCH=amd64 # Use "386" for 32-bit systems.
    curl -fsSL "https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v${VERSION}/docker-credential-gcr_${OS}_${ARCH}-${VERSION}.tar.gz" \
    | tar xz --to-stdout ./docker-credential-gcr \
    > /usr/bin/docker-credential-gcr && chmod +x /usr/bin/docker-credential-gcr

  3. Then, we have to configure Docker to use the Artifact Registry credentials when interacting with Artifact Registry

    docker-credential-gcr configure-docker –registries=us-central1-docker.pkg.dev

    After completing these steps, we can use Docker commands like `docker push`, `docker tag`, and `docker pull` with Artifact Registry.

Creating and Using a Maven Repository in Artifact Registry

  1. First, grant Cloud SDK authorization

    gcloud auth application-default login

  2. Then, create a Maven Repository:


    gcloud beta artifacts repositories create quickstart-maven-repo --repository-format=maven \
    --location=us-central1 [--description="Maven repository"]

    To create a Docker repository instead, modify `–repository-format=docker`.

    We can verify repository creation with this command:

    gcloud beta artifacts repositories list

    Also, set the default repository and location for simplified commands:


    gcloud config set artifacts/repository quickstart-maven-repo
    gcloud config set artifacts/location us-central1

  3. Now, generate configuration for `pom.xml`:

    gcloud beta artifacts print-settings mvn

  4. Push artifacts using:

    mvn deploy
    mvn release

Setting Up DevZero DevBox with Google Artifact Registry Access

  1. First, we have to configure the DevZero environment. So, add the following to the template to install Docker and Google Cloud CLI:


    scriptpolicy:
    - script: |
    apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
    gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
    https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
    tee /etc/apt/sources.list.d/docker.list > /dev/null
    apt-get update -y
    apt-get install docker-ce docker-ce-cli containerd.io -y
    usermod -aG docker devzero
    - script: |
    cd /home/devzero && curl https://sdk.cloud.google.com > install.sh
    bash install.sh --disable-prompts
    source /home/devzero/google-cloud-sdk/path.bash.inc
    runas: devzero

  2. Then, start a DevBox and run this command:

    source /home/devzero/google-cloud-sdk/path.bash.inc

    Add it to `.bashrc` or `.zshrc` to make this permanent.

  3. Next, authenticate with Google Cloud:

    gcloud init

  4. Finally, run the following command to configure Docker for Artifact Registry:

    gcloud auth configure-docker us-west1-docker.pkg.dev

Pull and Push Docker Images from Artifact Registry

  1. Pull an image:

    docker pull us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0

  2. Then, tag and push the image to the repository:


    docker tag us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 \
    us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
    docker push us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1

Troubleshooting Authentication Errors with Artifact Registry

Our experts have a quick fix if you run into the following error.

failed to authorize: failed to fetch anonymous token: unexpected status: 403 Forbidden

If authentication fails when pushing to Artifact Registry, resetting Docker may resolve the issue.


pkill Docker
sudo rm -rf "/usr/local/lib/Docker"
sudo rm -rf "/Library/PrivilegedHelperTools/com.docker.vmnetd"
sudo rm -rf "/Library/LaunchDaemons/com.docker.vmnetd.plist"
rm -rf "~/.docker"
rm -rf "~/Library/Containers/com.docker.docker"
rm -rf "~/Library/Application Support/Docker Desktop"
rm -rf "~/Library/Preferences/com.docker.docker.plist"
rm -rf "~/Library/Saved Application State/com.electron.docker-frontend.savedState"
rm -rf "~/Library/Group Containers/group.com.docker"
rm -rf "~/Library/Logs/Docker Desktop"
rm -rf "~/Library/Preferences/com.electron.docker-frontend.plist"
rm -rf "~/Library/Cookies/com.docker.docker.binarycookies"

Then, restart the machine and reinstall Docker.

Alternatively, we can downgrade the Docker version if the issue arises after an update.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

With the above steps, we can resolve most authentication and registry-related issues, ensuring smooth interaction with Google Artifact Registry.

In brief, our Support Experts demonstrated how to set up gcloud auth configure-docker for Artifact Registry.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF