在Google Cloud Platform,利用Cloud Storage作為Docker images的私有倉庫儲存空間。
553
在Google Cloud Platform,利用Cloud Storage作為Docker images的私有倉庫儲存空間。
已有Google Cloud Platform帳號。
已建立一個專案。(範例中的專案名稱為 Docker )
從左方選單進入 [儲存空間] → [Cloud Storage] → [儲存空間瀏覽器]。
建立一個bucket。(範例中的bucket名稱為 images_repo )
從左方選單進入 [運算] → [Compute Engine] → [VM執行個體]。
建立一個VM個體。(範例中VM名稱為 docker ,機器類型選擇弱一點的 g1-small ,開機磁碟為 Ubuntu 14.04 )
新的VM,先更新系統。
$sudo apt-get update && sudo apt-get upgrade -y
安裝Docker engine。
$wget -qO- https://get.docker.com/ | sh
利用gcloud提升權限。
$gcloud auth login
用瀏覽器開啟該網址,取得授權碼後,輸入授權碼。
因為是在Google Compute Engine上,所以使用Google版本的registry。
寫一個 docker_registry.sh 檔案,內容如下:(範例中的bucket名稱為 images_repo ,如有不同,請修改檔案第2行)
#!/bin/sh BUCKET=images_repo TOKEN=$(gcloud auth print-refresh-token)
#run registry
sudo docker pull google/docker-registry
sudo docker run -d
-e GCS_BUCKET=$BUCKET
-e GCP_OAUTH2_REFRESH_TOKEN=$TOKEN
-p 5000:5000
--restart=always
--name registry
google/docker-registry
執行 docker_registry.sh 。
$sudo sh docker_registry.sh
從官方registry下載image。
$sudo docker pull hello-world
重新標記image。
$sudo docker tag hello-world localhost:5000/hello-world
上傳image到私有倉庫。
$sudo docker push localhost:5000/hello-world
$sudo docker pull localhost:5000/hello-world-p 5000:5000 也要修改成 -p 其他port:5000 。docker pull minimum/google-docker-registry:latest