gpt4 book ai didi

azure - 使用 terraform 将 docker 镜像推送到 azure 容器注册表

转载 作者:行者123 更新时间:2023-12-02 06:23:22 25 4
gpt4 key购买 nike

我正在使用 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?

最佳答案

对于 docker 镜像,该名称实际上定义了将使用哪个注册表将镜像推送到(或从中获取)。因此,当您将镜像名称定义为 example 时,它将默认转到 DockerHub。

为了将镜像发送到您自己的注册表,无论注册表域位于何处,都必须将注册表域添加到镜像名称前面,如 here 中所述。 .

在上面链接中的示例中,mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine 将被推送到注册表 mcr.microsoft.com 而不是 DockerHub。

关于azure - 使用 terraform 将 docker 镜像推送到 azure 容器注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74002241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com