作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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/
我是一名优秀的程序员,十分优秀!