409 status error while deploying Nginx image through Terraform

Jaimin Joshi 50 Reputation points
2025-05-08T18:23:54.6066667+00:00

I am deploying an Nginx image in an Azure Container Group resource using Terraform.

Below is the code:

resource "azurerm_resource_group" "example" {
  name     = "test-rg"
  location = "EastUS"
}

resource "azurerm_container_group" "example" {
  name                = "example-continst"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  ip_address_type     = "Public"
  dns_name_label      = "aci-label"
  os_type             = "Linux"

  container {
    name   = "container1"
    image  = "nginx:latest"
    cpu    = "1"
    memory = "2"
    environment_variables = {
      TFC_AGENT_NAME = "test"

    }
    secure_environment_variables = {
      TFC_AGENT_TOKEN = var.tfc_token
    }

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

  
  tags = {
    environment = "testing"
  }
}


I am getting below error after trying multiple times at different times of day:

Error: creating Container Group (Subscription: "xxxxxxxxxxxxxxxxxxxx" Resource Group Name: "test-rg" Container Group Name: "example-continst"): performing ContainerGroupsCreateOrUpdate: unexpected status 409 (409 Conflict) with error: RegistryErrorResponse: An error response is received from the docker registry 'index.docker.io'. Please retry later. with azurerm_container_group.example on main.tf line 6, in resource "azurerm_container_group" "example": resource "azurerm_container_group" "example" {

Can you please suggest? Thank you

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
757 questions
{count} votes

Accepted answer
  1. Anusree Nashetty 4,380 Reputation points Microsoft External Staff Moderator
    2025-05-08T20:20:17.4433333+00:00

    Hi Jaimin Joshi,

    The error unexpected status 409 (409 Conflict) with error: RegistryErrorResponse: An error response is received from the docker registry 'index.docker.io'. Please retry later. indicates that Azure Container Instances (ACI) is having trouble pulling the nginx:latest image from Docker Hub (index.docker.io). This issue is not directly related to your Terraform configuration, but rather to Docker Hub's rate limiting or availability issues.

    Leverage Azure Container Registry (ACR): Store your Docker Hub images in an ACR instance and configure your ACI and deployments to pull from this private registry. This will help you avoid the Docker Hub rate limits.

    Please check this with similar issue: Azure Container issue pulling images on restart

    For your reference: https://github.com/datalust/seq-tickets/discussions/2223

    DockerHub Rate limit with Azure Container Instance

    Please check this document: RegistryErrorResponse when creating Azure Container Instance

    If you have any other queries, let me know. If the information provided above is helpful, please click on Upvote and Accept Answer on it.

    User's image

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Suwarna S Kale 3,316 Reputation points
    2025-05-08T19:45:03.9866667+00:00

    Hello Jaimin Joshi,

    Thank you for posting your question in the Microsoft Q&A forum. 

    The 409 Conflict error when deploying your Azure Container Group with Terraform typically indicates an issue with pulling the Nginx image from Docker Hub (index.docker.io). This could stem from rate-limiting, authentication issues, or temporary registry outages

    First, verify if Docker Hub is operational by checking https://www.dockerstatus.com/. If the registry is stable, authenticate with Docker Hub by adding registry_credential to your Terraform configuration, as anonymous pulls may hit rate limits. Example: 

    hcl 

    registry_credential

    {     

    server   = "index.docker.io"     

    username = var.docker_username     

    password = var.docker_password   

    }

    Alternatively, switch to Azure Container Registry (ACR) to avoid Docker Hub restrictions. If the issue persists, retry with exponential backoff or test a different image (e.g., nginx:alpine). For long-term stability, cache the image in ACR or use a private registry. 

    If the above answer helped, please do not forget to "Accept Answer" as this may help other community members to refer the info if facing a similar issue. Your contribution to the Microsoft Q&A community is highly appreciated. 

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.