最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

There is a good example how to configure DNS resolution within an Azure Container Group, section dnsConfig:

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/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 # 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: #az-container-create

There is a good example how to configure DNS resolution within an Azure Container Group, section dnsConfig: https://learn.microsoft/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/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 # 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/en-us/cli/azure/container?view=azure-cli-latest#az-container-create

Share Improve this question asked Mar 19 at 7:58 sl3dg3sl3dg3 5,21213 gold badges53 silver badges80 bronze badges 3
  • 1 As per the documentation learn.microsoft/en-us/azure/container-instances/… it is not possible to achieve this using CLI but you still leverage the requirement using ARM template deployement @sl3dg3 – Vinay B Commented Mar 19 at 9:35
  • 1 Since the 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. Let's say you create a yaml for aci-dns-config.yaml and then using that yaml create your aci- az container create --resource-group ACIResourceGroup --file aci-dns-config.yaml – Arko Commented Mar 19 at 13:44
  • Yes, I am now going the way of doing a yaml configuration file – sl3dg3 Commented Mar 20 at 3:53
Add a comment  | 

2 Answers 2

Reset to default 1

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/powershell:latest
      resources:
        requests:
          cpu: 1.0
          memoryInGB: 2.0
  dnsConfig:
    nameServers:
    - 10.0.0.10
    - 10.0.0.11
    searchDomains: contoso
  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 

Refer:

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

As discussed, the az container create command doesn't provide direct parameters to set custom DNS settings like --dns-servers or --dns-search

To configure custom DNS in Azure Container Instances, the recommended and currently supported approach is to define your container group in a YAML file using the dnsConfig section, then deploy it via Azure CLI using the --file option.

Create a virtual network and subnet (ACI must be deployed into a subnet for DNS settings to take effect)

az network vnet create \
  --resource-group ark \
  --name aci-vnet \
  --address-prefix 10.0.0.0/16 \
  --subnet-name aci-subnet \
  --subnet-prefix 10.0.0.0/24

Delegate the subnet to Microsoft.ContainerInstance:

az network vnet subnet update \
  --name aci-subnet \
  --resource-group ark \
  --vnet-name aci-vnet \
  --delegations Microsoft.ContainerInstance/containerGroups

Create a YAML definition (aci-dns-config.yaml) with your custom DNS servers and search domain:

apiVersion: '2021-07-01'
location: eastus
name: aci-dns-demo
properties:
  containers:
    - name: aci-dns-demo
      properties:
        image: mcr.microsoft/powershell:latest
        command:
          - /bin/bash
          - -c
          - echo hello; sleep 3600
        resources:
          requests:
            cpu: 1.0
            memoryInGB: 1.5
        ports:
          - port: 80
  osType: Linux
  ipAddress:
    type: Private
    ports:
      - port: 80
  dnsConfig:
    nameServers:
      - 10.0.0.10
      - 10.0.0.11
    searchDomains: contoso
  subnetIds:
    - id: /subscriptions/20df4f6c-0ab2-4a88-82d5-9d23dbddfc7d/resourceGroups/ark/providers/Microsoft.Network/virtualNetworks/aci-vnet/subnets/aci-subnet
type: Microsoft.ContainerInstance/containerGroups

Deploy the container group using the YAML file

az container create --resource-group ark --file aci-dns-config.yaml

You can even exec into the container and run cat /etc/resolv.conf to verify the DNS settings are applied.

So, in short- while you can't pass DNS config directly through az container create flags, you can fully configure it via YAML and deploy it cleanly with the CLI.

MS doc

发布评论

评论列表(0)

  1. 暂无评论