אחסון קובצי אימג' של קונטיינרים של Docker ב-Artifact Registry
בעזרת Artifact Registry תוכלו לנהל חבילות פרטיות וקובצי אימג' לקונטיינרים של Docker, במקום מרכזי אחד.
במדריך למתחילים הזה נסביר איך:
- יצירת מאגר Docker פרטי ב-Artifact Registry
- מגדירים אימות
- העלאת תמונה למאגר
- שליפת התמונה מהמאגר
לחצו על תראו לי איך כדי לקרוא הסבר מפורט על המשימה ישירות במסוף Google Cloud :
לפני שמתחילים
- נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Make sure that you have the following role or roles on the project: Artifact Registry Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Make sure that you have the following role or roles on the project: Artifact Registry Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
בחירת מעטפת
כדי להשלים את המדריך למתחילים הזה, משתמשים ב-Cloud Shell או במעטפת המקומית.
- Cloud Shell
- Cloud Shell היא סביבת מעטפת לניהול משאבים שמתארחים ב- Google Cloud. הוא מגיע עם Docker ו-Google Cloud CLI, ממשק שורת הפקודה הראשי של Google Cloud.
- מעטפת מקומית
- אם אתם מעדיפים להשתמש במעטפת המקומית, עליכם להתקין את Docker ואת ה-CLI של gcloud בסביבה שלכם.
הפעלת Cloud Shell
כדי להפעיל את Cloud Shell:
עוברים אל Google Cloud המסוף.
לוחצים על הלחצן Activate Cloud Shell (הפעלת Cloud Shell):
.
בחלק התחתון של המסוף ייפתח סשן של Cloud Shell בתוך מסגרת.
משתמשים בשורת הפקודות הזו כדי להריץ פקודות gcloud.
הגדרת מעטפת מקומית
כדי להתקין את ה-CLI של gcloud ואת Docker, מבצעים את השלבים הבאים:
מתקינים את ה-CLI של gcloud. כדי לעדכן התקנה קיימת, מריצים את הפקודה
gcloud components update.אם Docker עדיין לא מותקן, מתקינים אותו.
כדי לבצע פעולות במאגרי מידע, ל-Docker נדרשת גישה עם הרשאות. ב-Linux או ב-Windows, מוסיפים את המשתמש שמשמש להפעלת פקודות Docker לקבוצת האבטחה של Docker. אין צורך לבצע את השלב הזה ב-macOS כי Docker Desktop פועל במכונה וירטואלית כמשתמש Root.
Linux
קבוצת האבטחה של Docker נקראת
docker. כדי להוסיף את שם המשתמש, מריצים את הפקודה הבאה:sudo usermod -a -G docker ${USER}Windows
קבוצת האבטחה של Docker נקראת
docker-users. כדי להוסיף משתמש משורת הפקודה של האדמין, מריצים את הפקודה הבאה:net localgroup docker-users DOMAIN\USERNAME /add
כאשר:
- DOMAIN הוא הדומיין של Windows.
- USERNAME הוא שם המשתמש שלכם.
כדי שהשינויים במינוי לקבוצה ייכנסו לתוקף, צריך לצאת מהחשבון ולהיכנס אליו שוב. אם אתם משתמשים במכונה וירטואלית, יכול להיות שתצטרכו להפעיל אותה מחדש כדי שהשינויים בחברות ייכנסו לתוקף.
כדי לוודא ש-Docker פועל, מריצים את פקודת Docker הבאה, שמחזירה את השעה והתאריך הנוכחיים:
docker run --rm busybox dateהדגל
--rmמוחק את מופע הקונטיינר ביציאה.
יצירת מאגר Docker
יוצרים מאגר Docker כדי לאחסן את תמונת הדוגמה למדריך הזה למתחילים.
המסוף
פותחים את הדף Repositories במסוף Google Cloud .
לוחצים על הוספה יצירת מאגר.
מציינים את
quickstart-docker-repoכשם המאגר.בוחרים באפשרות Docker כפורמט ובאפשרות Standard כמצב.
בקטע Location Type, בוחרים באפשרות Region ואז בוחרים את המיקום
us-west1.לוחצים על יצירה.
המאגר נוסף לרשימת המאגרים.
gcloud
מריצים את הפקודה הבאה כדי ליצור מאגר Docker חדש בשם
quickstart-docker-repoבמיקוםus-west1עם התיאור 'docker repository'.gcloud artifacts repositories create quickstart-docker-repo --repository-format=docker \ --location=us-west1 --description="Docker repository" \ --project=PROJECTכאשר PROJECT הוא מזהה הפרויקט. Google Cloud
מריצים את הפקודה הבאה כדי לוודא שהמאגר נוצר.
gcloud artifacts repositories list \ --project=PROJECT
כדי לקבל מידע נוסף על פקודות Artifact Registry, מריצים את הפקודה gcloud artifacts.
הגדרת אימות
כדי לדחוף או למשוך תמונות, צריך להגדיר את Docker כך שישתמש ב-Google Cloud CLI כדי לאמת בקשות ל-Artifact Registry.
כדי להגדיר אימות למאגרי Docker באזור us-west1, מריצים את הפקודה הבאה:
gcloud auth configure-docker us-west1-docker.pkg.dev
הפקודה מעדכנת את ההגדרה של Docker. מעכשיו אפשר להתחבר ל-Artifact Registry בפרויקט Google Cloud כדי לשלוח תמונות ולמשוך אותן.
מידע על שיטות אימות אחרות זמין במאמר בנושא שיטות אימות.
איך מקבלים תמונה לדחיפה
במדריך למתחילים הזה, תדחפו תמונה לדוגמה בשם hello-app.
מריצים את הפקודה הבאה כדי למשוך את גרסה 1.0 של התמונה.
docker pull us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0
נתיבי תמונות ב-Artifact Registry כוללים כמה חלקים. בדוגמה הזו של תמונה:
-
us-docker.pkg.devהוא שם המארח של קובצי אימג' של קונטיינרים שמאוחסנים במאגרי Docker ב-Artifact Registry, שכולל את מיקום המאגר (us). -
google-samplesהוא מזהה הפרויקט. -
containersהוא מזהה המאגר. -
/gke/hello-appהוא הנתיב לתמונה במאגרcontainers.
הוספת התמונה למאגר
לפני שמעבירים בדחיפה את קובץ האימג' של Docker ל-Artifact Registry, צריך לתייג אותו עם שם המאגר.
תיוג התמונה עם שם מאגר
תיוג קובץ אימג' של Docker עם שם מאגר מגדיר את הפקודה docker push כך שתדחוף את התמונה למיקום ספציפי. במדריך למתחילים הזה, מיקום המארח הוא us-west1-docker.pkg.dev.
מריצים את הפקודה הבאה כדי לתייג את התמונה כ-quickstart-image:tag1:
docker tag us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 \ us-west1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
כאשר:
-
us-west1הוא המיקום של המאגר. -
us-west1-docker.pkg.devהוא שם המארח של מאגר Docker שיצרתם. - PROJECT הוא מזהה הפרויקט ב- Google Cloud .
אם מזהה הפרויקט מכיל נקודתיים (
:), כדאי לעיין במאמר בנושא פרויקטים בהיקף הדומיין. -
quickstart-docker-repoהוא המזהה של המאגר שיצרתם. -
quickstart-imageהוא שם התמונה שרוצים להשתמש בה במאגר. שם התמונה יכול להיות שונה משם התמונה המקומית. במדריך למתחילים הזה, התמונה תאוחסן ישירות מתחת למזהה המאגרquickstart-docker-repo. -
tag1הוא תג שמוסיפים לקובץ האימג' של Docker. אם לא ציינתם תג, Docker יחיל את תג ברירת המחדלlatest.
עכשיו אפשר להעלות את התמונה למאגר שיצרתם.
העברת האימג' בדחיפה ל-Artifact Registry
אחרי שמגדירים אימות ומתייגים את התמונה המקומית, אפשר להעלות את התמונה למאגר שיצרתם.
כדי לדחוף את קובץ האימג' של Docker, מריצים את הפקודה הבאה:
docker push us-west1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
:), כדאי לעיין במאמר בנושא פרויקטים בהיקף הדומיין.
שליפת התמונה מ-Artifact Registry
כדי למשוך את התמונה מ-Artifact Registry למחשב המקומי, מריצים את הפקודה הבאה:
docker pull us-west1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
:), כדאי לעיין במאמר בנושא פרויקטים בהיקף הדומיין.
latest: Pulling from [PROJECT-ID]/quickstart-image:tag1 Digest: sha256:70c42... Status: Image is up to date for us-west1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
הסרת המשאבים
כדי לא לצבור חיובים לחשבון Google Cloud על המשאבים שבהם השתמשתם בדף הזה, פועלים לפי השלבים הבאים:
לפני שמסירים את המאגר, צריך לוודא שכל התמונות שרוצים לשמור זמינות במיקום אחר.
כדי למחוק את המאגר:
המסוף
פותחים את הדף Repositories במסוף Google Cloud .
ברשימת המאגרים, בוחרים במאגר
quickstart-docker-repo.לוחצים על Delete.
gcloud
כדי למחוק את מאגר quickstart-docker-repo, מריצים את הפקודה הבאה:
gcloud artifacts repositories delete quickstart-docker-repo --location=us-west1
המאמרים הבאים
- מידע נוסף על עבודה עם תמונות של מאגרי תגים
- מידע נוסף על Docker
- אפשר גם לקרוא את המשאבים שלנו בנושא DevOps ולעיין בתוכנית המחקר DevOps Research and Assessment (DORA).