{"id":1360,"library":"azure-mgmt-containerinstance","title":"Azure Container Instance Management","description":"The `azure-mgmt-containerinstance` library provides a client for managing Azure Container Instances, allowing programmatic creation, update, and deletion of container groups and related resources. It is part of the larger Azure SDK for Python and is currently at version 10.1.0, with frequent updates aligning with Azure service API changes and broader SDK release cycles.","status":"active","version":"10.1.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/containerinstance/azure-mgmt-containerinstance","tags":["azure","management","container","cloud","aci"],"install":[{"cmd":"pip install azure-mgmt-containerinstance azure-identity","lang":"bash","label":"Install with identity"}],"dependencies":[{"reason":"Required for authenticating to Azure services using modern credential types.","package":"azure-identity","optional":false}],"imports":[{"symbol":"ContainerInstanceManagementClient","correct":"from azure.mgmt.containerinstance import ContainerInstanceManagementClient"},{"note":"Old authentication method from v8 and earlier; modern SDK uses azure-identity.","wrong":"from msrestazure.azure_active_directory import ServicePrincipalCredentials","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.containerinstance import ContainerInstanceManagementClient\n\n# --- Environment Variables (Replace with your actual values or ensure they are set) ---\nSUBSCRIPTION_ID = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"YOUR_SUBSCRIPTION_ID\")\nRESOURCE_GROUP_NAME = os.environ.get(\"AZURE_RESOURCE_GROUP\", \"my-aci-rg\")\nLOCATION = os.environ.get(\"AZURE_LOCATION\", \"eastus\")\nCONTAINER_GROUP_NAME = os.environ.get(\"AZURE_ACI_NAME\", \"my-aci-container-group\")\n\nif SUBSCRIPTION_ID == \"YOUR_SUBSCRIPTION_ID\":\n    raise ValueError(\"Please set the AZURE_SUBSCRIPTION_ID environment variable.\")\n\n# Authenticate using DefaultAzureCredential (looks for env vars, managed identity, etc.)\ncredential = DefaultAzureCredential()\n\n# Create a ContainerInstanceManagementClient\nclient = ContainerInstanceManagementClient(credential, SUBSCRIPTION_ID)\n\n# Define the container group\ncontainer_group_body = {\n    \"location\": LOCATION,\n    \"containers\": [\n        {\n            \"name\": \"mycontainer\",\n            \"image\": \"mcr.microsoft.com/azuredocs/aci-helloworld\",\n            \"resources\": {\n                \"requests\": {\n                    \"cpu\": 1.0,\n                    \"memory_in_gb\": 1.5\n                }\n            },\n            \"ports\": [{\"port\": 80}]\n        }\n    ],\n    \"os_type\": \"Linux\",\n    \"ip_address\": {\n        \"type\": \"Public\",\n        \"ports\": [\n            {\n                \"protocol\": \"TCP\",\n                \"port\": 80\n            }\n        ]\n    }\n}\n\nprint(f\"Creating container group '{CONTAINER_GROUP_NAME}' in resource group '{RESOURCE_GROUP_NAME}'...\")\n\n# Create or update the container group (this returns a poller object)\nlro_poller = client.container_groups.begin_create_or_update(\n    resource_group_name=RESOURCE_GROUP_NAME,\n    container_group_name=CONTAINER_GROUP_NAME,\n    container_group=container_group_body\n)\n\n# Wait for the operation to complete and get the result\ncontainer_group = lro_poller.result()\n\nprint(f\"Container group '{container_group.name}' created/updated successfully.\")\nprint(f\"IP Address: {container_group.ip_address.ip}\")\n\n# To delete the container group (optional)\n# print(f\"Deleting container group '{CONTAINER_GROUP_NAME}'...\")\n# delete_poller = client.container_groups.begin_delete(\n#     resource_group_name=RESOURCE_GROUP_NAME,\n#     container_group_name=CONTAINER_GROUP_NAME\n# )\n# delete_poller.result()\n# print(f\"Container group '{CONTAINER_GROUP_NAME}' deleted.\")","lang":"python","description":"This quickstart demonstrates how to authenticate with `DefaultAzureCredential` and create a simple Azure Container Instance (ACI) using the `ContainerInstanceManagementClient`. It sets up a container group with a single public-facing container running a hello-world image. Remember to set your Azure Subscription ID, Resource Group Name, and Location in environment variables or directly in the script."},"warnings":[{"fix":"Use `from azure.identity import DefaultAzureCredential` for authentication and initialize the client directly with `ContainerInstanceManagementClient(credential, subscription_id)`.","message":"Starting from version 9.0.0, the `ContainerInstanceManagementClient` no longer accepts a `base_url` parameter. Authentication methods have also shifted from `msrestazure` credentials (e.g., `ServicePrincipalCredentials`) to `azure-identity` (e.g., `DefaultAzureCredential`).","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Update calls to `client.container_groups.begin_create_or_update` to use `resource_group_name_param` instead of `resource_group_name`.","message":"In version 9.0.0 and later, the `create_or_update` method for `ContainerGroups` changed parameter names. Specifically, `resource_group_name` was renamed to `resource_group_name_param` for clarity and consistency across Azure SDKs.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Always call `.result()` on the poller object (e.g., `lro_poller.result()`) to wait for the operation to complete and retrieve the final resource object or status in synchronous clients. For asynchronous clients, you'd `await` the poller methods.","message":"Many Azure management operations, especially those that create or update resources (e.g., `begin_create_or_update`, `begin_delete`), are long-running operations (LROs). These methods return a poller object, not the final resource directly.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure the resource group exists before attempting to deploy container instances into it. You might need to use `azure-mgmt-resource` to create resource groups programmatically if they don't exist.","message":"Resource group operations (creating container instances) require the specified resource group to already exist in Azure. If it doesn't, the operation will fail.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}