This document explains how to manually set up gcr.io
repositories in
Artifact Registry.
If you want to create gcr.io
repositories in Artifact Registry using
customer-managed encryption keys (CMEK), then
complete the steps in Before you begin, and then follow
the instructions in Manual repository creation.
Before you begin
Install the Google Cloud CLI if it is not already installed. For an existing installation, run the following command to update components to the latest versions:
gcloud components update
Enable the Artifact Registry and Resource Manager APIs. The gcloud CLI uses the Resource Manager API to check for one of the required permissions.
Run the following command:
gcloud services enable \ cloudresourcemanager.googleapis.com \ artifactregistry.googleapis.com
Learn about pricing for Artifact Registry before you begin the transition.
Required roles
To get the permissions that you need to set up gcr.io
repositories,
ask your administrator to grant you the
following IAM roles:
-
To create Artifact Registry repositories and grant access to individual repositories:
Artifact Registry Administrator (
roles/artifactregistry.admin
) on the Google Cloud project -
To view and manage existing Container Registry configuration applied to Cloud Storage storage buckets:
Storage Admin (
roles/storage.admin
) on the Google Cloud project -
To create a
gcr.io
repository the first time you push an image to agcr.io
hostname: Artifact Registry Create-on-push Writer (roles/artifactregistry.createOnPushWriter
) on the Google Cloud project -
To grant repository access at the project level:
Project IAM Admin (
roles/resourcemanager.projectIamAdmin
) on the Google Cloud project -
To list enabled services in an organization:
Cloud Asset Viewer (
roles/cloudasset.viewer
) on the organization
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Limitations
The following limitations apply to Artifact Registry gcr.io
repositories:
When transitioning from Container Registry, you cannot map a Container Registry host to an Artifact Registry repository in a different project.
Each Container Registry hostname maps to only one corresponding Artifact Registry
gcr.io
repository in the same multi-region.Names for
gcr.io
repositories are predefined and you can't modify them.
If you need more control over the location of your repositories, you can
transition to pkg.dev
repositories in Artifact Registry. Since pkg.dev
repositories don't have any support for the gcr.io
domain, this transition
approach requires more changes to your existing automation and workflows. See
Choose a transition option to learn about feature differences.
Create repositories
Create gcr.io
repositories so that you can configure access for your users and
copy existing Container Registry images to Artifact Registry before you enable
redirection.
Manual repository creation
Manually create gcr.io
repositories if you want to use
customer-managed encryption keys (CMEK) to encrypt
repository content or if there is a location constraint in your
Google Cloud organization that blocks creation of new resources in
specific locations.
To manually create a gcr.io
repository:
If you are using CMEK, create the key you will use with this repository and grant permissions to use the key. See Enabling customer-managed encryption keys.
Add the repository.
Console
Open the Repositories page in the Google Cloud console.
Click Create Repository.
Specify the repository name.
Container Registry hostname Artifact Registry repository name gcr.io gcr.io asia.gcr.io asia.gcr.io eu.gcr.io eu.gcr.io us.gcr.io us.gcr.io Specify Docker as the repository format.
Under Location Type, specify the multi-region for the repository:
Container Registry hostname Artifact Registry repository location Artifact Registry repository name gcr.io us gcr.io asia.gcr.io asia asia.gcr.io eu.gcr.io europe eu.gcr.io us.gcr.io us us.gcr.io Add a description for the repository. Do not include sensitive data, since repository descriptions are not encrypted.
In the Encryption section, choose the encryption mechanism for the repository.
- Google-managed key - Encrypt repository content with a Google-owned and Google-managed key.
- Customer-managed key - Encrypt repository content with a key that you control through Cloud Key Management Service. For key setup instructions, see Setting up CMEK for repositories.
Click Create.
gcloud
Run the following command to create a new repository:
gcloud artifacts repositories create REPOSITORY \ --repository-format=docker \ --location=LOCATION \ --description=DESCRIPTION \ --kms-key=KMS-KEY
Replace the following values:
REPOSITORY is the name of the repository.
Container Registry hostname Artifact Registry repository name gcr.io gcr.io asia.gcr.io asia.gcr.io eu.gcr.io eu.gcr.io us.gcr.io us.gcr.io LOCATION is the multi-region for the repository:
Container Registry hostname Artifact Registry repository location Artifact Registry repository name gcr.io us gcr.io asia.gcr.io asia asia.gcr.io eu.gcr.io europe eu.gcr.io us.gcr.io us us.gcr.io DESCRIPTION is a description of the repository. Do not include sensitive data, since repository descriptions are not encrypted.
KMS-KEY is the full path to the Cloud KMS encryption key, if you are using a customer-managed encryption key to encrypt repository contents. The path is in the format:
projects/KMS-PROJECT/locations/KMS-LOCATION/keyRings/KEY-RING/cryptoKeys/KEY
Replace the following values:
- KMS-PROJECT is the project where your key is stored.
- KMS-LOCATION is the location of the key.
- KEY-RING is the name of the key ring.
- KEY is the name of the key.
You can confirm that the repository is created by listing your repositories with the following command:
gcloud artifacts repositories list
Before you redirect traffic to your new repositories, you need to make sure that your existing automation can access the repository. The next step is configuring permissions to grant access to repositories.
Grant permissions to repositories
Container Registry uses Cloud Storage roles to control access. Artifact Registry has its own IAM roles and these roles separate read, write, and repository administration roles more clearly than Container Registry.
To quickly map existing permissions granted on storage buckets to suggested Artifact Registry roles, use the role mapping tool.
Alternatively, you can view a list of principals with access to storage buckets using the Google Cloud console.
- In the Google Cloud console, go to the Cloud Storage Buckets page.
Click the storage bucket for the registry host you want to view. In the bucket names,
PROJECT-ID
is your Google Cloud project ID.- gcr.io:
artifacts.PROJECT-ID.appspot.com
- asia.gcr.io:
asia.artifacts.PROJECT-ID.appspot.com
- eu.gcr.io:
eu.artifacts.PROJECT-ID.appspot.com
- us.gcr.io:
us.artifacts.PROJECT-ID.appspot.com
- gcr.io:
Click the Permissions tab.
On the Permissions tab, click the View by role subtab.
Expand a role to view the principals who have that role.
The list includes IAM roles granted directly on the bucket and roles inherited from the parent project. Based on the role, you can choose the most appropriate Artifact Registry role to to grant.
- Cloud Storage and basic roles
Grant users and service accounts that currently access Container Registry with access to Artifact Registry repositories. For Cloud Storage roles inherited from the parent project, you should verify that the principal currently uses Container Registry. Some principals might only access other Cloud Storage buckets that are unrelated to Container Registry.
The basic roles Owner, Editor, and Viewer that existed prior to IAM have limited access to storage buckets. They do not intrinsically give all of the access to Cloud Storage resources that their names imply and provide additional permissions for other Google Cloud services. Verify which users and service accounts require access to Artifact Registry and use the role mapping table to help you grant the right roles if Artifact Registry access is appropriate.
The following table maps Artifact Registry roles based on the permissions granted by predefined Cloud Storage roles for Container Registry access.
Required access Current role Artifact Registry role Where to grant role Pull images only (read only) Storage Object Viewer
(roles/storage.objectViewer
)Artifact Registry Reader
(roles/artifactregistry.reader)
Artifact Registry repository or Google Cloud project - Push and pull images (read and write)
- Delete images
Storage Legacy Bucket Writer
(roles/storage.legacyBucketWriter
)Artifact Registry Repository Administrator
(roles/artifactregistry.repoAdmin)
Artifact Registry repository or Google Cloud project Create a gcr.io repository in Artifact Registry the first time an image is pushed to a gcr.io hostname in a project. Storage Admin
(roles/storage.admin
)Artifact Registry Create-on-push Repository Administrator
(roles/artifactregistry.createOnPushRepoAdmin)
Google Cloud project Create, manage, and delete repositories Storage Admin
(roles/storage.admin
)Artifact Registry Administrator
(roles/artifactregistry.Admin)
Google Cloud project - Service agent roles inherited from the project
Default service accounts for Google Cloud services have their own roles granted at the project level. For example the service agent for Cloud Run has the Cloud Run Service Agent role.
In most cases, these service agent roles contain equivalent default permissions for Container Registry and Artifact Registry and you do not need to make any additional changes if you are running Artifact Registry in the same project as your existing Container Registry service.
Refer to the service agent role reference for details on the permissions in service agent roles.
- Custom roles
Use the role mapping table to help you decide on the role to grant to users or service accounts based on the level of access they require.
For instructions on granting Artifact Registry roles, see Configure roles and permissions.
Copy containers from Container Registry
We recommend using our automatic migration tool to copy your images from Container Registry to Artifact Registry.
If you want to use other tooling to copy your images, see Copy images from Container Registry
Set up other features
This section describes configuration for other features that you might have set up in Container Registry.
Artifact Analysis
Artifact Analysis supports both Container Registry and Artifact Registry. Both products use the same Artifact Analysis APIs for image metadata and vulnerability scanning, and the same Pub/Sub topics for Artifact Analysis notifications.
However, the following actions only occur when redirection is enabled:
- Automatic scanning of
gcr.io
repositories in Artifact Registry. - Including
gcr.io
repository activity in Pub/Sub notifications.
You can continue to use gcloud container images
commands to list notes and occurrences associated with gcr.io
image paths.
Container Registry | Artifact Registry |
---|---|
Scans for OS and language package vulnerabiities with on-demand scanning
in images with a supported OS. Automatic scanning only returns OS
vulnerability information.
Learn more about types of
scanning.
|
Scans for OS and lanaguage package vulnerabiities with both on-demand and
automatic scanning.
Learn more about types of
scanning.
|
Pub/Sub notifications
Artifact Registry publishes changes to the same gcr
topic as
Container Registry. No additional configuration is required if you already use
Pub/Sub with Container Registry in the same project as
Artifact Registry. However, Artifact Registry does not publish
messages for gcr.io
repositories until you enable redirection.
If you set up Artifact Registry in a separate project, the gcr
topic
might not exist. For setup instructions, see
Configuring Pub/Sub notifications.
Enable redirection of gcr.io
traffic
After you have created your gcr.io
repositories
and configured permissions and authentication for your
third-party clients, you can enable redirection of gcr.io
traffic.
If you encounter an issue after enabling redirection, you can route traffic back
to Container Registry by running the
gcloud artifacts settings disable-upgrade-redirection
command, and then turn on redirection again when you have addressed
the issue.
Verify permissions to enable redirection
To enable redirection, you must have these permissions at the project level:
artifactregistry.projectsettings.update
- Permissions to update Artifact Registry project settings. This permission is in the Artifact Registry Administrator role (roles/artifactregistry.admin
).storage.buckets.update
- Permissions to update storage buckets across the entire project. This permission is in the Storage Admin role (roles/storage.admin
).
If you don't have these permissions, ask an administrator to grant them at the project level.
The following commands grant the Artifact Registry Administrator and Storage Admin roles on a project.
gcloud projects add-iam-policy-binding PROJECT_ID \
--member='user:PRINCIPAL' \
--role='roles/artifactregistry.admin'
gcloud projects add-iam-policy-binding PROJECT_ID \
--member='user:PRINCIPAL' \
--role='roles/storage.admin'
Replace the following values:
- PROJECT_ID is Google Cloud project ID.
- PRINCIPAL is the email address for the account that you are updating.
For example
my-user@example.com
Validate project setup
To validate your project setup, run the following command:
gcloud artifacts settings enable-upgrade-redirection \
--project=PROJECT_ID --dry-run
Replace PROJECT_ID with your Google Cloud project ID.
Artifact Registry checks for repositories that map to Container Registry hostnames.
Although Artifact Registry can create the missing gcr.io
repositories for
you when you enable redirection, we recommend creating them first so that you
can perform these actions before turning on redirection:
- Configure repository-level permissions.
- Copy images from Container Registry that you still want to use.
- Perform any additional configuration.
Turn on redirection
To turn on redirection for gcr.io
traffic:
To enable redirection, run the following command:
gcloud artifacts settings enable-upgrade-redirection \
--project=PROJECT_ID
Replace PROJECT_ID with your Google Cloud project ID.
Artifact Registry starts turning on redirection.
To check the current status of redirection, run the following command:
gcloud artifacts settings describe
When redirection is enabled, the result is:
legacyRedirectionState: REDIRECTION_FROM_GCR_IO_ENABLED
All traffic to gcr.io
, asia.gcr.io
, eu.gcr.io
, and us.gcr.io
is
redirected, even if you did not create gcr.io
repositories for all
Container Registry hostnames. If you push an image to a hostname that doesn't
have a corresponding Artifact Registry repository, Artifact Registry creates the repository
if you have a role with the artifactregistry.repositories.createOnPush
permission. The predefined roles Create-on-push Writer
(artifactregistry.createOnPushWriter
) and Create-on-push Repository
Administrator (artifactregistry.createOnPushRepoAdmin
) have this permission.
With redirection enabled, you can test your automation and verify that you can
push and pull images using your new gcr.io
repositories.
Verify redirection
Verify that pull and push requests to gcr.io
hostnames are working.
Push a test image to one of your
gcr.io
repositories using itsgcr.io
path.Tag the image using the
gcr.io
path. For example, this command tags the imagelocal-image
asus.gcr.io/my-project/test-image
:docker tag local-image us.gcr.io/my-project/test-image
Push the image you tagged. For example, this command pushes the image
us.gcr.io/my-project/test-image
:docker push us.gcr.io/my-project/test-image
List images in the repository to verify that the image was uploaded successfully. For example, to list images in
us.gcr.io/my-project
, run the command:gcloud container images list --repository=us.gcr.io/my-project
Pull the image from the repository using its Container Registry path. For example, this command pulls the image
us.gcr.io/my-project/test-image
.docker pull us.gcr.io/my-project/test-image
After this initial test, verify that your existing automation to build and deploy images works as expected, including:
- Users and service accounts that use Container Registry can still push, pull, and deploy images when redirection is enabled.
- Your automation only pushes images to existing repositories.
- If Artifact Analysis vulnerability scanning is enabled, scanning
identifies images with vulnerabilities in
gcr.io
repositories. - If you use Binary Authorization, your existing policies work correctly for images
deployed from
gcr.io
repositories. - Configured Pub/Sub subscriptions include notifications for
changes in your
gcr.io
repositories.
Clean up Container Registry images
When redirection is enabled, commands to delete images in gcr.io
paths
delete images in the corresponding Artifact Registry gcr.io
repository.
Delete commands to delete images in gcr.io
paths don't delete images stored on
Container Registry hosts.
To safely remove all Container Registry images, delete the Cloud Storage buckets for each Container Registry hostname.
To delete each Container Registry storage bucket:
Console
- Go to the Cloud Storage page in the Google Cloud console.
Select the storage bucket to delete. In the bucket names,
PROJECT-ID
is your Google Cloud project ID.- gcr.io:
artifacts.PROJECT-ID.appspot.com
- asia.gcr.io:
asia.artifacts.PROJECT-ID.appspot.com
- eu.gcr.io:
eu.artifacts.PROJECT-ID.appspot.com
- us.gcr.io:
us.artifacts.PROJECT-ID.appspot.com
- gcr.io:
Click Delete. A confirmation dialog box appears.
To confirm deletion, enter the bucket name and then click Delete.
gcloud
If you want to bulk delete a hundred thousand or more images in a bucket, avoid using the gcloud CLI since the deletion process takes a long time to complete. Use the Google Cloud console to perform the operation instead. For more information, see deleting Cloud Storage objects in bulk.
To delete a bucket, use the gcloud storage rm
command with the --recursive
flag.
gcloud storage rm gs://BUCKET-NAME --recursive
Replace BUCKET-NAME
with the Container Registry storage
bucket name. In the bucket names, PROJECT-ID
is your
Google Cloud
project ID.
- gcr.io:
artifacts.PROJECT-ID.appspot.com
- asia.gcr.io:
asia.artifacts.PROJECT-ID.appspot.com
- eu.gcr.io:
eu.artifacts.PROJECT-ID.appspot.com
- us.gcr.io:
us.artifacts.PROJECT-ID.appspot.com
The response looks like the following example:
Removing gs://artifacts.my-project.appspot.com/...
If other Google Cloud services are running in the same Google Cloud project, leave the Container Registry API enabled. If you try to disable the Container Registry API. Container Registry displays a warning if other services with a configured dependency are enabled in the project. Disabling the Container Registry API automatically disables any services in the same project with a configured dependency, even if you are not currently using Container Registry with those services.
What's next
- Try the Docker quickstart.
- Learn about
gcr.io
repositories.