With a simple example, step by step, push Docker Image to GCP Artifact Registry.
Artifact Registry improves and extends upon the existing capabilities of Container Registry, such as customer-managed encryption keys, VPC-SC support, Pub/Sub notifications, and more, providing a foundation for major upgrades in security, scalability, and control.
The sample is running in Windows 11 PowerShell 7.3.1.
GCP Push and pull images
Pre-work
- Create a GCP project (ex. artifact-registry-microsystem).
- Docker installed on the local machine.
Google Cloud CLI Installer
You can refer to the following webpage if you have not installed gcloud CLI: Install the gcloud CLI.
After installation, you will be asked to log in and choose a default project name. Once done, you can enter the gcloud command in PowerShell.
Create Repository
Select the GCP Project you want to join, and add Artifact Registry. The relevant setting options are as follows:
- Name: quickstart-docker-repo (Repository name, you can set it yourself)
- Format: Docker
- Location Type: Region
- Region: us-central1
Setting Auth
Executing the following commands will modify the contents of the docker configuration:
gcloud auth configure-docker \
us-central1-docker.pkg.dev
Check the docker configuration, and you will find that the credHelpers block has been added. Execute the following commands:
cat $env:UserProfile\.docker\config.json
The results are as follows:
{
"credsStore": "desktop",
"credHelpers": {
"us-central1-docker.pkg.dev": "gcloud"
}
}
Pull Docker Image
Next, you can create your own or get a Docker Image from Docker Hub:
docker pull nginx
Tag Docker Image
Before pushing the docker image, add a tag to the docker image with the hostname and repository name.
The tag format is: <hostname>/<project-name>/<repository-name>/<image-name>:<tag>
docker tag nginx \
us-central1-docker.pkg.dev \
/artifact-registry-microsystex \
/quickstart-docker-repo \
/nginx-image:tag1
- us-central1: the region of the repository host
- docker.pkg.dev: adding this suffix after the region will be the hostname
- artifact-registry-microsystex: GCP Project ID, this is the project name you can create by yourself
- nginx-image: Docker image name
Push Docker Image
Finally, Docker can be pushed to a private registry:
docker push
us-central1-docker.pkg.dev \
/artifact-registry-microsystex \
/quickstart-docker-repo \
/nginx-image:tag1
References:
Artifact Registry: the next generation of Container Registry
No comments:
Post a Comment