'How to connect Azure Multi-Instance Container to Azure Virtual Network

Situation : I have created a azure resource. which has a container registry, virtual network with firewall.

Problem : While creating a single container instance you can specify the virtual network, so that the firewall rules, public static ip and all networking settings gets attached to the container. But, while deploying multi container instance its done only using command with docker compose on azure context.

Question : I would like to know how to link the multi container instance to the virtual network ?



Solution 1:[1]

To deploy a multi-container group with the az container create command in the Azure CLI, you must specify the container group configuration in a YAML file. Then pass the YAML file as a parameter to the command.

This YAML file defines a container group named "myContainerGroup" with two containers, a privte IP address, and two exposed ports. The containers are deployed from public Microsoft images. The first container in the group runs an internet-facing web application. The second container, the sidecar, periodically makes HTTP requests to the web application running in the first container via the container group's local network.

You need to require subnet delegate permissions ie Microsoft.ContainerInstance/containerGroups. in your existing Vnet's Subnet

enter image description here

yaml code

apiVersion: '2021-07-01'
location: westus2
name: myContainerGroup
properties:
  containers:
  - name: aci-tutorial-app
    properties:
      image: mcr.microsoft.com/azuredocs/aci-helloworld:latest
      resources:
        requests:
          cpu: 1
          memoryInGb: 1.5
      ports:
      - port: 80
      - port: 8080
  - name: aci-tutorial-sidecar
    properties:
      image: mcr.microsoft.com/azuredocs/aci-tutorial-sidecar
      resources:
        requests:
          cpu: 1
          memoryInGb: 1.5
  osType: Linux
  ipAddress:
    type: Private
    ports:
    - protocol: tcp
      port: 80
    - protocol: tcp
      port: 8080
  restartPolicy: Always
  subnetIds:
    - id: /subscriptions/b83c1XXXXXX-b5ba-2XXXX74c23f/resourceGroups/v-XX-XXX/providers/Microsoft.Network/virtualNetworks/Vnet1/subnets/default
      name: default
tags: {exampleTag: tutorial}
type: Microsoft.ContainerInstance/containerGroups

enter image description here

enter image description here

Reference :Tutorial: Deploy a multi-container group using a YAML file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RahulKumarShaw-MT