![](/img/trans.png)
[英]Authenticate Google Compute Engine (GCE) to Pull Image from Google Container Registry (GCR)
[英]Pulling from google container registry in Jenkins scripted pipeline on compute engine vm
我在谷歌雲計算引擎虛擬機上設置了 Jenkins。 Docker 已安裝,我成功地使用腳本管道拉取並運行公共 docker 圖像。 不過,我似乎無法從 Google 容器注冊表中提取信息,而且我找不到任何有關如何在腳本化管道中執行此操作的示例。 這是我的詹金斯文件:
node {
checkout scm
docker.image('mysql:5.7').withRun('--env MYSQL_DATABASE=my_db --env MYSQL_ROOT_PASSWORD=password -p 3306:3306') { c ->
docker.image('mysql:5.7').inside("--link ${c.id}:db") {
/* Wait until mysql service is up */
sh 'while ! mysqladmin ping -hdb --silent; do sleep 1; done'
}
/* Fails here */
docker.image('gcr.io/my-project/my-image').withRun("--link ${c.id}:db --env MYSQL_HOST=localhost --env MYSQL_USER=root --env MYSQL_PWD=password --env MYSQL_DB=my_db --network=host")
}
}
似乎因為我在計算引擎虛擬機上,所以不需要為 Jenkins 進行任何憑證配置(顯然我錯了)。 我已經在虛擬機上運行gcloud auth configure-docker
,我可以輕松地 ssh 並通過簡單的docker pull
從 gcr.io 中拉出我想要的圖像。 當 jenkins 嘗試拉取時,我收到Error response from daemon: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
Error response from daemon: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
。
有任何想法嗎?
編輯:我發現用docker.withRegistry()
包裝我的 pull 步驟,但這需要我通過 Jenkins 接口添加我的 gcloud 憑據。 我需要這樣做似乎很奇怪,因為 Jenkins 已經在具有正確身份驗證的計算引擎虛擬機上運行,並且 docker 已正確配置為能夠從 gcr.io 中提取。 Jenkins(或 docker 管道插件)是否有某種特殊方式正在運行 docker,它在某種程度上與 docker 在虛擬機上手動運行時具有的身份驗證不同?
破解了這個,這有點傻。 雖然我確實確實為虛擬機上的用戶正確設置了身份驗證,但我沒有為虛擬機上的jenkins用戶執行此操作。 在 ssh-ing 進入虛擬機后,我需要做的是:
sudo su jenkins
gcloud auth configure-docker
這會將 docker 的 gcloud 配置添加到 jenkins 的主目錄。 那么您就不需要withRegistry
或任何額外的 jenkins 憑證配置。 如果您在虛擬機上執行此操作,則干凈整潔。
看起來您在 GCE VM 上遇到了 Jenkins 和 Docker 的一些身份驗證問題。
該文檔可能對 [1] 有所幫助,而且,您是否有機會尋找幫助者 [2]?
[1] https://googleapis.dev/python/google-api-core/latest/auth.html#using-google-compute-engine
[2] https://cloud.google.com/container-registry/docs/advanced-authentication#helpers
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.