Pushing Your Docker Image to Artifact Registry

In the previous two labs, you worked locally with your container image. In this lab, we will look at publishing your image to Google Artifact Registry. By pushing your image to an external registry, this allows others (with the right IAM permissions) to pull down your image to run themselves.

As part of your lab setup, an Artifact Registry repository was provisioned for you. You can get the name of it with the following gcloud command:

gcloud artifacts repositories list

Note the repository name and location.

Pushing to Artifact Registry #

Before you can push or pull an image to Artifact Registry in Cloud Shell, you need to configure Docker to authenticate requests to it in the region that it is located, which is us-central1 in this case. Run the following command to set up the authentication:

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

To push your Docker image, you first need to tag it with the repository name. The following commands tag the image as random-facts-app:1.0 and random-facts-app:latest.

docker tag random-facts-app:1.0 us-central1-docker.pkg.dev/<YOUR_PROJECT_ID>/<YOUR_REPOSITORY_NAME>/random-facts-app:1.0
docker tag random-facts-app:latest us-central1-docker.pkg.dev/<YOUR_PROJECT_ID>/<YOUR_REPOSITORY_NAME>/random-facts-app:latest

Now you can push the Docker image to Artifact Registry by running the following command:

docker push us-central1-docker.pkg.dev/<YOUR_PROJECT_ID>/<YOUR_REPOSITORY_NAME>/random-facts-app --all-tags

To verify that your image was successfully pushed, use the following gcloud command:

gcloud artifacts docker images list us-central1-docker.pkg.dev/<YOUR_PROJECT_ID>/<YOUR_REPOSITORY_NAME>

Congratulations! You have successfully pushed your Docker image to Artifact Registry! Please demonstrate your accomplishment to an instructor.