Container Registry
目錄
- Docker
- 倉庫
- Google Container Registry
- 實作
1. Docker
Docker
Docker 容器的啟動時間是秒級的,大量節省開發、測試、部署的時間。
-
映像檔(Image):
映像檔可以用來建立 Docker 容器。
-
容器(Container):
它可以被啟動、開始、停止、刪除,每個容器都是相互隔離、保證安全的。
-
倉庫 (Registry):
是存放Docker Image的倉庫
Docker 工作流程圖
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Docker 常用指令
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
2. 倉庫
倉庫
Repository (倉庫) 是集中存放映像檔的地方
Registry (倉庫註冊伺服器) 是存放與管理多個倉庫
倉庫類型:公開(Public)、私有(Private)
- 公開倉庫: Docker Hub
- 私有倉庫: Gitlab、harbor
Google Container Registry (GCR)
Azure Container Registry (ACR)
Amazon Elastic Container Registry (ECR)
3. Google Container Registry
GCR 功能與特色
-
安全的私人 Docker Registry
-
自動建立及部署映像檔
-
深度安全漏洞掃描
-
快速搜尋與容器標記
-
快速的高可用性存取
GCR 名稱格式
漏洞掃描(Vulnerability scanning)
-
Container Registry中透過Container Analysis進行映像檔執行漏洞掃描,並監控漏洞資訊以使其保持最新狀態。
-
兩個主要任務:
1.新增掃描:將映像檔上傳到Container Registry
2.持續分析:當Container Analysis從漏洞來源接收新的和更新的漏洞資訊時,它會重新分析容器
-
支援作業系統 Alpine、CentOS、Debian、RedHat 和 Ubuntu 的各不同版本掃瞄。
容器分析(Container Analysis)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
容器分析(Container Analysis) 時代演進
- 2017年11月22日 容器分析在Alpha中可用
- 2018年 9月 6日 容器分析提供Beta版
- 2019年 8月26日 容器分析API的V1版本現已全面上市
- 2019年 9月20日 容器分析現已全面推出
- 2020年 3月16日 Artifact Registry是Container Registry的演進版本,現已提供Beta版。
漏洞的嚴重性級別
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
GCR 權限
- 啟用Container Registry 的漏洞掃描服務帳號會自動添加以三下種
[PROJECT-NUMBER]@containerregistry.iam.gserviceaccount.com
service-[PROJECT_NUMBER]@container-analysis.iam.gserviceaccount.com
service-[PROJECT_NUMBER]@gcp-sa-containerscanning.iam.gserviceaccount.com
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Cloud Storage角色和權限
- GCR使用Storage作為容器映像檔底層儲存空間
- 默認服務帳戶的後綴為
[PROJECT_NUMBER]-compute@developer.gserviceaccount.com

GCR 費用
- Storage 存儲空間
- Docker 映像檔使用的輸出流量
- Docker 映像檔的漏洞掃描(選擇啟用此服務)
映像檔的漏洞掃描費用
- 每個掃描映像檔 $0.26 美元–2020/9/01起,完整計費
- 會自動掃描各個新推送的映像檔
- 如要掃描現有的映像檔,您必須重新推送
- 映像檔中新增、編輯標記均不會產生費用
預估漏洞掃描费用
- 可使用Cloud Shell 開啟Open Editor新增 cost-estimation.sh文件,內容如下:

執行 bash cost-estimation.sh文件

實作
- 前置作業
- Docker run nginx
- Docker build image
- Docker push GCR
- Deploy to GCE
實作 - 前置作業
- GCP專案需挷定帳單
- 開通storage 推送、拉取的權限
- GCR需進行身份驗證,gcloud作為Docker憑證,以便直接在gcloud 中配合Docker 使用
gcloud auth login

gcloud auth configure-docker

- 啟用 Container Registry API

- 啟用 漏洞掃描

實作1 - Docker run nginx
docker run -d --name nginx -p 80:80 nginx
docker cp containerID:/usr/share/nginx/html/index.html .
實作2 - Docker build image
- 新增一個Dockerfile

- 執行docker bulid 語法
docker build -t nginxhello2 .

實作3:Docker push GCR
- 標記本地映像:
docker tag [SOURCE_IMAGE] [HOSTNAME]/[PROJECT-ID]/[IMAGE]
docker tag nginxhello2 gcr.io/sc-lab-2/nginxhello2:1.1

- 推送到Container Registry:
docker push [HOSTNAME]/[PROJECT-ID]/[IMAGE]
docker push gcr.io/sc-lab-2/nginxhello2:1.1

3. 確認有無推送成功

實作4:Deploy to GCE
- Deploy to GCE

- 建立完成


參考來源:
官方文件
https://cloud.google.com/container-registry/docs
Docker 工作流程圖
https://kknews.cc/code/vak8np4.html