我正在使用 terraform 在 Azure 中為我的專案預配基礎架構。
基礎設施的一部分是一個容器注冊表,用于存盤將由 kubernates 使用的 docker 鏡像。因為目前一切都是使用 terraform 配置的,所以我也在嘗試構建和推送影像。我找到了kreuzwerker/docker可能可以完成這項作業的提供商。
目前我有這個代碼:
provider "docker" {
registry_auth {
address = azurerm_container_registry.example.login_server
username = azurerm_container_registry.example.admin_username
password = azurerm_container_registry.example.admin_password
}
}
resource "docker_registry_image" "example" {
name = "example"
keep_remotely = false
build {
context = path.cwd
dockerfile = "Dockerfile"
}
}
似乎影像已經構建,但是在將其推送到注冊表時出現此錯誤:
?
│ Error: resourceDockerRegistryImageCreate: Unable to get authConfig for registry: no auth config found for registry registry-1.docker.io in auth configs: map[string]types.AuthConfig{"***.azurecr.io":types.AuthConfig{Username:"***", Password:"***", Auth:"", Email:"", ServerAddress:"https://***.azurecr.io", IdentityToken:"", RegistryToken:""}}
│
│ with docker_registry_image.backend,
│ on docker.tf line 1, in resource "docker_registry_image" "backend":
│ 1: resource "docker_registry_image" "backend" {
│
?
我認為它正在嘗試推送,registry-1.docker.io但這不是正確的注冊表。所以我嘗試了
provider "docker" {
host = azurerm_container_registry.example.login_server
registry_auth {
address = azurerm_container_registry.example.login_server
username = azurerm_container_registry.example.admin_username
password = azurerm_container_registry.example.admin_password
}
}
但后來我得到這個錯誤:
?
│ Error: Error initializing Docker client: unable to parse docker host `***.azurecr.io`
│
│ with provider["registry.terraform.io/kreuzwerker/docker"],
│ on provider.tf line 8, in provider "docker":
│ 8: provider "docker" {
│
?
如何使用此提供程式將影像推送到正確的 ACR?
uj5u.com熱心網友回復:
對于 docker 影像,如果影像實際定義了將用于將影像推送到(或從中獲取)的注冊表的名稱。因此,當您將鏡像名稱定義為 時example,默認情況下它會轉到 DockerHub。
為了將映像發送到您自己的注冊表,無論在哪里,注冊表域都必須添加到映像名稱之前,如此處所述。
在上面鏈接的示例中,mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine將被推送到注冊表mcr.microsoft.com而不是 DockerHub。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/511811.html
