azurednsazure-container-instances

Configure DNS in Azure Container Groups (ACI) with az cli


There is a good example how to configure DNS resolution within an Azure Container Group, section dnsConfig: https://learn.microsoft.com/en-us/azure/container-instances/container-instances-custom-dns

apiVersion: '2021-07-01'
location: westus
name: pwsh-vnet-dns
properties:
  containers:
  - name: pwsh-vnet-dns
    properties:
      command:
      - /bin/bash
      - -c
      - echo hello; sleep 10000
      environmentVariables: []
      image: mcr.microsoft.com/powershell:latest
      ports:
      - port: 80
      resources:
        requests:
          cpu: 1.0
          memoryInGB: 2.0
  dnsConfig:
    nameServers:
    - 10.0.0.10 # DNS Server 1
    - 10.0.0.11 # DNS Server 2
    searchDomains: contoso.com # DNS search suffix
  ipAddress:
    type: Private
    ports:
    - port: 80
  subnetIds:
    - id: /subscriptions/<subscription-ID>/resourceGroups/ACIResourceGroup/providers/Microsoft.Network/virtualNetworks/aci-vnet/subnets/aci-subnet
  osType: Linux
tags: null
type: Microsoft.ContainerInstance/containerGroups

Is there any way to get it done with Azure CLI: az container create ... I could not find anything pointing into this direction: https://learn.microsoft.com/en-us/cli/azure/container?view=azure-cli-latest#az-container-create


Solution

  • Configure DNS in Azure Container Groups (ACI) with az cli

    Thanks Arko for specifying the similar input and guiding in the right direction.

    Yes, az container create command doesn't have an explicit --dns-servers flag, you'll need to create a YAML configuration file and deploy it using Azure CLI.

    I tried a demo configuration which is in the line with the requirement mentioned below

    Demo configuration:

    aci-deployment.yml

    apiVersion: '2021-07-01'
    location: Italy North
    name: vksb-container-group
    properties:
      containers:
      - name: vksb-container
        properties:
          image: mcr.microsoft.com/powershell:latest
          resources:
            requests:
              cpu: 1.0
              memoryInGB: 2.0
      dnsConfig:
        nameServers:
        - 10.0.0.10
        - 10.0.0.11
        searchDomains: contoso.com
      osType: Linux
      subnetIds:
        - id: /subscriptions/SubID/resourceGroups/testvks-rg/providers/Microsoft.Network/virtualNetworks/vksb-vnet/subnets/vksb-subnet
    

    Deployment:

    az container create --resource-group testvks-rg --file aci-deployment.yml 
    

    enter image description here

    enter image description here

    Refer:

    https://learn.microsoft.com/en-us/azure/container-instances/container-instances-custom-dns#deploy-your-container-group