Pulling and Running Images
Introduction and Lesson Outcome
Welcome to the fourth lesson in our course on working with container registries. You've made excellent progress building your Artifact Registry expertise, learning what Google Artifact Registry is, creating secure repositories, and mastering the complete workflow of building and pushing Docker images to Artifact Registry. Now that you have container images stored securely in Artifact Registry, it's time to learn the other half of the container workflow: pulling and running those images.
Understanding the pull and run workflow is crucial because it completes the full container lifecycle. While pushing images to Artifact Registry represents the development and build phase, pulling images represents the deployment and runtime phase. This lesson focuses on consuming images from Artifact Registry, which mirrors exactly how Google Cloud services like Google Kubernetes Engine (GKE) and Cloud Run retrieve and run your containerized applications in production environments.
The practical outcome you'll achieve in this lesson is pulling an image from your Artifact Registry repository and running it locally as a container. You'll master the key commands docker pull for retrieving images from Artifact Registry and docker run for starting containers from those images, completing the essential skills needed for working with container registries in production environments.
What You Need (Repo URI, Region, Permissions)
Before pulling images from Artifact Registry, you need to gather key information that identifies where your images are stored in Google Cloud. This information ensures that your pull operations target the correct repository and region where your images are stored.
In Google Artifact Registry, images are identified by a URI that follows a specific format: {region}-docker.pkg.dev/{project-id}/{repository-name}/{image-name}:{tag}. Let's break down each component:
- Region: The Google Cloud region where your repository exists (e.g.,
us-central1,us-east1,europe-west1). This must match the region you specified when creating your repository. - Project ID: Your Google Cloud project identifier, which is a unique string that identifies your Google Cloud project (not to be confused with the project number).
- Repository name: The name you gave your repository when you created it (e.g.,
my-web-app). - Image name: The name of the specific image within your repository (e.g.,
my-web-app). - Tag: The version identifier for your image (e.g.,
latest,v1.0,dev).
You can retrieve your repository details using the gcloud artifacts repositories describe command. This command displays information about your repository, including its location and format:
The output shows your repository details, including the format (which should be DOCKER) and the location. To construct your complete image URI, you'll combine these elements. For example, if your project ID is my-project-123, your repository is named my-web-app in the us-central1 region, and your image is named my-web-app, your complete URI would be:
For pulling images from Artifact Registry, your Google Cloud credentials need specific IAM permissions. The essential role for pulling images is roles/artifactregistry.reader, which grants the necessary permissions to read repository contents and download images. This role includes permissions to list repositories, view repository metadata, and download container images.
You can verify your current permissions or grant the reader role using:
Most Google Cloud environments that have Artifact Registry access include these pull permissions by default, since pulling images is a common operation for deployment services like GKE and Cloud Run. However, if you encounter permission errors during the pull process, verify that your account or service account has the roles/artifactregistry.reader role for the specific repository.
