Microsoft Azure Container Instance Client Library for Python providing comprehensive management capabilities for containerized applications in Azure cloud.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
This document provides comprehensive type definitions for all Azure Container Instance resources including container groups, containers, volumes, and networking configurations.
class ContainerGroup:
"""
Primary resource representing a collection of containers that share lifecycle and resources.
Args:
location (str): Azure region for deployment (e.g., "East US", "West Europe")
containers (List[Container]): List of containers in the group
os_type (str): Operating system type ("Linux" or "Windows")
restart_policy (str, optional): Restart policy ("Always", "OnFailure", "Never")
ip_address (IpAddress, optional): Public IP configuration
volumes (List[Volume], optional): Shared storage volumes
image_registry_credentials (List[ImageRegistryCredential], optional): Registry auth
dns_config (DnsConfiguration, optional): Custom DNS settings
subnet_ids (List[ContainerGroupSubnetId], optional): Virtual network integration
identity (ContainerGroupIdentity, optional): Managed identity configuration
init_containers (List[InitContainerDefinition], optional): Init containers
encryption_properties (EncryptionProperties, optional): Encryption settings
tags (Dict[str, str], optional): Resource tags
Properties:
name (str): Container group name (read-only)
id (str): Azure resource ID (read-only)
type (str): Azure resource type (read-only)
provisioning_state (str): Current provisioning state (read-only)
instance_view (ContainerGroupPropertiesInstanceView): Runtime status (read-only)
Example:
container_group = ContainerGroup(
location="East US",
containers=[
Container(
name="web-server",
image="nginx:latest",
resources=ResourceRequirements(
requests=ResourceRequests(memory_in_gb=1.0, cpu=1.0)
)
)
],
os_type="Linux",
restart_policy="Always",
ip_address=IpAddress(
type="Public",
ports=[ContainerPort(port=80)]
),
tags={"environment": "production", "team": "web"}
)
"""class Container:
"""
Individual container definition within a container group.
Args:
name (str): Container name (unique within group)
image (str): Container image reference (e.g., "nginx:1.21", "mcr.microsoft.com/app:latest")
resources (ResourceRequirements): CPU and memory requirements
command (List[str], optional): Override container entrypoint
ports (List[ContainerPort], optional): Exposed ports
environment_variables (List[EnvironmentVariable], optional): Environment variables
volume_mounts (List[VolumeMount], optional): Volume mount points
liveness_probe (ContainerProbe, optional): Health check configuration
readiness_probe (ContainerProbe, optional): Readiness check configuration
security_context (SecurityContextDefinition, optional): Security settings
Properties:
instance_view (ContainerPropertiesInstanceView): Runtime status (read-only)
Example:
container = Container(
name="api-server",
image="myregistry.azurecr.io/api:v1.2.3",
command=["python", "app.py", "--port=8080"],
resources=ResourceRequirements(
requests=ResourceRequests(memory_in_gb=2.0, cpu=1.5),
limits=ResourceLimits(memory_in_gb=4.0, cpu=2.0)
),
ports=[
ContainerPort(port=8080, protocol="TCP")
],
environment_variables=[
EnvironmentVariable(name="APP_ENV", value="production"),
EnvironmentVariable(name="DB_PASSWORD", secure_value="secret-password")
],
volume_mounts=[
VolumeMount(name="app-storage", mount_path="/data", read_only=False)
]
)
"""class ResourceRequirements:
"""
CPU and memory resource specifications for containers.
Args:
requests (ResourceRequests): Minimum guaranteed resources
limits (ResourceLimits, optional): Maximum allowed resources
Example:
resources = ResourceRequirements(
requests=ResourceRequests(
memory_in_gb=1.0, # 1 GB minimum memory
cpu=0.5, # 0.5 CPU cores minimum
gpu=GpuResource(count=1, sku="K80") # Optional GPU
),
limits=ResourceLimits(
memory_in_gb=2.0, # 2 GB maximum memory
cpu=1.0 # 1 CPU core maximum
)
)
"""
class ResourceRequests:
"""
Minimum resource requirements for a container.
Args:
memory_in_gb (float): Memory in gigabytes (e.g., 0.5, 1.0, 2.0)
cpu (float): CPU cores (e.g., 0.1, 0.5, 1.0, 2.0)
gpu (GpuResource, optional): GPU resource specification
"""
class ResourceLimits:
"""
Maximum resource limits for a container.
Args:
memory_in_gb (float): Maximum memory in gigabytes
cpu (float): Maximum CPU cores
gpu (GpuResource, optional): Maximum GPU resources
"""
class GpuResource:
"""
GPU resource specification.
Args:
count (int): Number of GPU instances
sku (str): GPU SKU ("K80", "P100", "V100")
Example:
gpu = GpuResource(count=2, sku="V100")
"""class IpAddress:
"""
Public IP address configuration for container groups.
Args:
ports (List[ContainerPort]): Exposed ports and protocols
type (str): IP address type ("Public" or "Private")
ip (str, optional): Static IP address (for private IPs)
dns_name_label (str, optional): DNS label for FQDN generation
auto_generated_domain_name_label_scope (str, optional): Scope for auto DNS labels
dns_name_label_reuse_policy (str, optional): DNS label reuse policy
Properties:
fqdn (str): Fully qualified domain name (read-only)
Example:
# Public IP with custom DNS label
public_ip = IpAddress(
type="Public",
dns_name_label="my-app-instance",
ports=[
ContainerPort(port=80, protocol="TCP"),
ContainerPort(port=443, protocol="TCP")
]
)
# Private IP for VNet integration
private_ip = IpAddress(
type="Private",
ip="10.0.0.100",
ports=[ContainerPort(port=8080)]
)
"""
class ContainerPort:
"""
Port specification for containers and IP addresses.
Args:
port (int): Port number (1-65535)
protocol (str, optional): Protocol ("TCP" or "UDP", defaults to "TCP")
Example:
ports = [
ContainerPort(port=80, protocol="TCP"), # HTTP
ContainerPort(port=443, protocol="TCP"), # HTTPS
ContainerPort(port=53, protocol="UDP") # DNS
]
"""
class DnsConfiguration:
"""
Custom DNS configuration for container groups.
Args:
name_servers (List[str]): List of DNS server IP addresses
search_domains (List[str], optional): DNS search domains
options (str, optional): DNS resolver options
Example:
dns_config = DnsConfiguration(
name_servers=["8.8.8.8", "8.8.4.4"],
search_domains=["company.local"],
options="ndots:2 edns0"
)
"""class Volume:
"""
Storage volume that can be mounted in containers.
Args:
name (str): Volume name (unique within container group)
azure_file (AzureFileVolume, optional): Azure Files share
empty_dir (EmptyDirVolume, optional): Empty directory volume
secret (SecretVolume, optional): Secret-based volume
git_repo (GitRepoVolume, optional): Git repository volume
Note: Exactly one volume type must be specified.
Example:
# Azure Files volume
file_volume = Volume(
name="shared-storage",
azure_file=AzureFileVolume(
share_name="app-data",
storage_account_name="mystorageaccount",
storage_account_key="storage-key",
read_only=False
)
)
# Secret volume
secret_volume = Volume(
name="app-secrets",
secret=SecretVolume(
secret_name="ssl-certs",
default_mode=0o400
)
)
"""
class AzureFileVolume:
"""
Azure Files share volume configuration.
Args:
share_name (str): Name of the Azure Files share
storage_account_name (str): Storage account name
storage_account_key (str): Storage account access key
read_only (bool, optional): Mount as read-only (defaults to False)
"""
class VolumeMount:
"""
Volume mount configuration for containers.
Args:
name (str): Name of volume to mount (must match Volume.name)
mount_path (str): Path inside container where volume is mounted
read_only (bool, optional): Mount as read-only (defaults to False)
Example:
volume_mounts = [
VolumeMount(name="app-data", mount_path="/data", read_only=False),
VolumeMount(name="config", mount_path="/etc/app", read_only=True)
]
"""
class SecretVolume:
"""
Secret-based volume for sensitive data.
Args:
secret_name (str): Name of the secret
default_mode (int, optional): Default file permissions (octal)
items (Dict[str, str], optional): Key-to-filename mapping
"""
class GitRepoVolume:
"""
Git repository volume for code deployment.
Args:
repository (str): Git repository URL
directory (str, optional): Target directory name
revision (str, optional): Git revision (branch, tag, or commit)
"""class EnvironmentVariable:
"""
Environment variable configuration for containers.
Args:
name (str): Environment variable name
value (str, optional): Plain text value
secure_value (str, optional): Encrypted/secure value
Note: Specify either 'value' or 'secure_value', not both.
Example:
env_vars = [
EnvironmentVariable(name="APP_PORT", value="8080"),
EnvironmentVariable(name="DEBUG", value="false"),
EnvironmentVariable(name="API_KEY", secure_value="secret-api-key"),
EnvironmentVariable(name="DB_CONNECTION", secure_value="connection-string")
]
"""
class ImageRegistryCredential:
"""
Container registry authentication credentials.
Args:
server (str): Registry server hostname
username (str, optional): Registry username
password (str, optional): Registry password
identity (str, optional): Managed identity resource ID for authentication
identity_url (str, optional): Identity endpoint URL
Example:
# Username/password authentication
registry_cred = ImageRegistryCredential(
server="myregistry.azurecr.io",
username="registry-user",
password="registry-password"
)
# Managed identity authentication
managed_identity_cred = ImageRegistryCredential(
server="myregistry.azurecr.io",
identity="/subscriptions/sub-id/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity"
)
"""class ContainerProbe:
"""
Health check probe configuration for containers.
Args:
exec_probe (ContainerExec, optional): Command-based probe
http_get (ContainerHttpGet, optional): HTTP-based probe
initial_delay_seconds (int, optional): Delay before first probe
period_seconds (int, optional): Probe interval
failure_threshold (int, optional): Failures before marking unhealthy
success_threshold (int, optional): Successes before marking healthy
timeout_seconds (int, optional): Probe timeout
Example:
# HTTP health check
liveness_probe = ContainerProbe(
http_get=ContainerHttpGet(
path="/health",
port=8080,
scheme="HTTP"
),
initial_delay_seconds=30,
period_seconds=10,
failure_threshold=3
)
# Command-based health check
readiness_probe = ContainerProbe(
exec_probe=ContainerExec(
command=["curl", "-f", "http://localhost:8080/ready"]
),
initial_delay_seconds=5,
period_seconds=5
)
"""
class ContainerHttpGet:
"""
HTTP-based health check configuration.
Args:
path (str, optional): HTTP request path
port (int): Port number for health check
scheme (str, optional): HTTP scheme ("HTTP" or "HTTPS")
http_headers (List[HttpHeader], optional): Custom HTTP headers
"""
class ContainerExec:
"""
Command-based health check configuration.
Args:
command (List[str]): Command and arguments to execute
"""
class HttpHeader:
"""
HTTP header for health check requests.
Args:
name (str): Header name
value (str): Header value
"""class ContainerGroupIdentity:
"""
Managed identity configuration for container groups.
Args:
type (str): Identity type ("SystemAssigned", "UserAssigned", "SystemAssigned,UserAssigned", "None")
user_assigned_identities (Dict[str, UserAssignedIdentity], optional): User-assigned identities
Properties:
principal_id (str): System-assigned identity principal ID (read-only)
tenant_id (str): System-assigned identity tenant ID (read-only)
Example:
# System-assigned identity
system_identity = ContainerGroupIdentity(type="SystemAssigned")
# User-assigned identity
user_identity = ContainerGroupIdentity(
type="UserAssigned",
user_assigned_identities={
"/subscriptions/sub-id/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-identity":
UserAssignedIdentity()
}
)
"""class ContainerExecRequest:
"""
Request configuration for container command execution.
Args:
command (List[str]): Command and arguments to execute
terminal_size (ContainerExecRequestTerminalSize, optional): Terminal dimensions
Example:
# Simple command execution
exec_request = ContainerExecRequest(
command=["ls", "-la", "/app"]
)
# Interactive shell with terminal size
shell_request = ContainerExecRequest(
command=["/bin/bash"],
terminal_size=ContainerExecRequestTerminalSize(rows=24, cols=80)
)
"""
class ContainerExecRequestTerminalSize:
"""
Terminal size specification for interactive command execution.
Args:
rows (int): Number of terminal rows
cols (int): Number of terminal columns
"""
class ContainerExecResponse:
"""
Response from container command execution.
Properties:
web_socket_uri (str): WebSocket URI for command interaction
password (str): Authentication password for WebSocket connection
"""
class ContainerAttachResponse:
"""
Response from container attachment operation.
Properties:
web_socket_uri (str): WebSocket URI for container attachment
password (str): Authentication password for WebSocket connection
"""
class Logs:
"""
Container logs response.
Properties:
content (str): Log content as text
"""from azure.mgmt.containerinstance.models import (
ContainerGroup, Container, ContainerGroupProperties,
ResourceRequirements, ResourceRequests, ResourceLimits,
IpAddress, ContainerPort, EnvironmentVariable,
Volume, VolumeMount, AzureFileVolume,
ImageRegistryCredential, ContainerProbe, ContainerHttpGet,
ContainerGroupIdentity
)
# Complete container group with all features
container_group = ContainerGroup(
location="East US",
containers=[
Container(
name="web-app",
image="myregistry.azurecr.io/webapp:v2.1.0",
resources=ResourceRequirements(
requests=ResourceRequests(memory_in_gb=2.0, cpu=1.0),
limits=ResourceLimits(memory_in_gb=4.0, cpu=2.0)
),
ports=[ContainerPort(port=80), ContainerPort(port=443)],
environment_variables=[
EnvironmentVariable(name="ASPNETCORE_ENVIRONMENT", value="Production"),
EnvironmentVariable(name="ConnectionStrings__Default", secure_value="connection-string")
],
volume_mounts=[
VolumeMount(name="app-data", mount_path="/data"),
VolumeMount(name="logs", mount_path="/logs")
],
liveness_probe=ContainerProbe(
http_get=ContainerHttpGet(path="/health", port=80),
initial_delay_seconds=30,
period_seconds=10
)
)
],
os_type="Linux",
restart_policy="Always",
ip_address=IpAddress(
type="Public",
dns_name_label="my-production-app",
ports=[ContainerPort(port=80), ContainerPort(port=443)]
),
volumes=[
Volume(
name="app-data",
azure_file=AzureFileVolume(
share_name="appdata",
storage_account_name="mystorageaccount",
storage_account_key="storage-key"
)
),
Volume(
name="logs",
azure_file=AzureFileVolume(
share_name="logs",
storage_account_name="mystorageaccount",
storage_account_key="storage-key"
)
)
],
image_registry_credentials=[
ImageRegistryCredential(
server="myregistry.azurecr.io",
username="registry-user",
password="registry-password"
)
],
identity=ContainerGroupIdentity(type="SystemAssigned"),
tags={
"environment": "production",
"application": "web-app",
"version": "v2.1.0"
}
)Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-containerinstance