【问题标题】:Deploy container on Azure with Terraform from private DockerHub repo使用私有 DockerHub 存储库中的 Terraform 在 Azure 上部署容器
【发布时间】:2021-07-12 12:31:26
【问题描述】:

我正在将一个应用程序从一个容器和一个存储在 DockerHub 中的图像部署到 Azure。当我在 DockerHub 中部署存储库时,它是公开的,因此我可以轻松部署它。但是,我希望将存储库设为私有并且仍然能够部署它。我可以以某种方式将 DockerHub 的凭据传递给 terraform 配置吗?

目前这是我用来部署容器的方法。这一切都有效,但我真的很想将 repo 设为私有。

resource "azurerm_container_group" "cg" {
  name                = "mycontainer"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  ip_address_type     = "public"
  dns_name_label      = "mycontainer"
  os_type             = "Linux"

  container {
    name   = "mycontainer"
    image  = "myuser/myimage:tag"
    cpu    = "0.5"
    memory = "1.5"

    ports {
      port     = 80
      protocol = "TCP"
    }
  }
}

【问题讨论】:

    标签: azure docker terraform


    【解决方案1】:

    您只需将azurerm_container_group 的属性image_registry_credential 添加到您的私有注册表凭据中,如下所示:

    resource "azurerm_container_group" "cg" {
      name                = "mycontainer"
      location            = azurerm_resource_group.rg.location
      resource_group_name = azurerm_resource_group.rg.name
      ip_address_type     = "public"
      dns_name_label      = "mycontainer"
      os_type             = "Linux"
    
      container {
        name   = "mycontainer"
        image  = "myuser/myimage:tag"
        cpu    = "0.5"
        memory = "1.5"
    
        ports {
          port     = 80
          protocol = "TCP"
        }
      }
    
      image_registry_credential {
        username = "xxx"
        password = "xxx"
        server   = "server_url"
      }
    }
    

    【讨论】:

    • 我收到此错误riginal Error: Code="InaccessibleImage" Message="The image 'myuser/myimage:tag' in container group 'mycontainer' is not accessible.。我使用正确的凭据和 hub.docker.com 作为服务器 url
    • @everspader 可能图像名称不正确。你可以试试看能不能在本地登录私有注册中心拉取他们的镜像。
    • 图片名称正确。我是存储图像的 repo 的所有者,所以我正在玩弄它,当我在没有 image_registry_credential 块的情况下拥有公开的 repo 时,可以拉图像,但当 repo 是私有的并且块时不能正在使用凭据
    • @everspader 你能给出你私人注册表中带有标签的图像的截图吗?
    • @everspader 所以你把它设置为image=everspader/myimage:0.1?我这边一切正常。
    【解决方案2】:

    图片需要: "serverurl/用户名/myimage:tag"

    【讨论】:

      猜你喜欢
      • 2020-10-03
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 2012-12-19
      • 2020-01-29
      相关资源
      最近更新 更多