How do I use --ports and --protocol with the az container CLI?

jamie 20 Reputation points
2023-10-25T15:47:38.59+00:00

The documentation for the Azure Container CLI specifies that --ports and --protocol is available to use, but it doesn't give an example of how to set different ports to different protocol types.

For example, if I want to expose --ports 80 19132 (via az container create) there isn't a way to specify that port 80 is TCP and 19132 is UDP. I tried setting --protocol UDP but this causes both port 80 and 19132 to bind to UDP.

How can I specify different protocols for different ports?

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
758 questions
0 comments No comments
{count} votes

Accepted answer
  1. TP 126.4K Reputation points Volunteer Moderator
    2023-10-25T16:54:47.2866667+00:00

    Hi,

    One method is to create using .yaml file instead:

    az container create -g MyResourceGroup -f myapp.yaml
    
    

    In the yaml file you can list each port with its protocol, similar to below:

    additional_properties: {}
    apiVersion: '2023-05-01'
    extended_location: null
    location: westus
    name: myapp
    properties:
      containers:
      - name: myapp
        properties:
          environmentVariables: []
          image: mcr.microsoft.com/azuredocs/aci-helloworld:latest
          ports:
          - port: 80
            protocol: TCP
          - port: 19132
            protocol: UDP
          resources:
            requests:
              cpu: 1.0
              memoryInGB: 1.5
      initContainers: []
      ipAddress:
        ip: 10.0.3.4
        ports:
        - port: 80
          protocol: TCP
        - port: 19132
          protocol: UDP
        type: Private
      isCustomProvisioningTimeout: false
      osType: Linux
      provisioningTimeoutInSeconds: 1800
      restartPolicy: OnFailure
      sku: Standard
      subnetIds:
      - id: /subscriptions/<subscriptionID>/resourceGroups/myresourcegroup/providers/Microsoft.Network/virtualNetworks/myresourcegroup-vnet/subnets/default
    tags: {}
    type: Microsoft.ContainerInstance/containerGroups
    
    

    YAML reference: Azure Container Instances

    https://learn.microsoft.com/en-us/azure/container-instances/container-instances-reference-yaml

    Please click Accept Answer and upvote if above was useful.

    Thanks.

    -TP


0 additional answers

Sort by: Most 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.