0
# Resource Models and Types
1
2
This document provides comprehensive type definitions for all Azure Container Instance resources including container groups, containers, volumes, and networking configurations.
3
4
## Core Resource Models
5
6
### ContainerGroup { .api }
7
8
```python
9
class ContainerGroup:
10
"""
11
Primary resource representing a collection of containers that share lifecycle and resources.
12
13
Args:
14
location (str): Azure region for deployment (e.g., "East US", "West Europe")
15
containers (List[Container]): List of containers in the group
16
os_type (str): Operating system type ("Linux" or "Windows")
17
restart_policy (str, optional): Restart policy ("Always", "OnFailure", "Never")
18
ip_address (IpAddress, optional): Public IP configuration
19
volumes (List[Volume], optional): Shared storage volumes
20
image_registry_credentials (List[ImageRegistryCredential], optional): Registry auth
21
dns_config (DnsConfiguration, optional): Custom DNS settings
22
subnet_ids (List[ContainerGroupSubnetId], optional): Virtual network integration
23
identity (ContainerGroupIdentity, optional): Managed identity configuration
24
init_containers (List[InitContainerDefinition], optional): Init containers
25
encryption_properties (EncryptionProperties, optional): Encryption settings
26
tags (Dict[str, str], optional): Resource tags
27
28
Properties:
29
name (str): Container group name (read-only)
30
id (str): Azure resource ID (read-only)
31
type (str): Azure resource type (read-only)
32
provisioning_state (str): Current provisioning state (read-only)
33
instance_view (ContainerGroupPropertiesInstanceView): Runtime status (read-only)
34
35
Example:
36
container_group = ContainerGroup(
37
location="East US",
38
containers=[
39
Container(
40
name="web-server",
41
image="nginx:latest",
42
resources=ResourceRequirements(
43
requests=ResourceRequests(memory_in_gb=1.0, cpu=1.0)
44
)
45
)
46
],
47
os_type="Linux",
48
restart_policy="Always",
49
ip_address=IpAddress(
50
type="Public",
51
ports=[ContainerPort(port=80)]
52
),
53
tags={"environment": "production", "team": "web"}
54
)
55
"""
56
```
57
58
### Container { .api }
59
60
```python
61
class Container:
62
"""
63
Individual container definition within a container group.
64
65
Args:
66
name (str): Container name (unique within group)
67
image (str): Container image reference (e.g., "nginx:1.21", "mcr.microsoft.com/app:latest")
68
resources (ResourceRequirements): CPU and memory requirements
69
command (List[str], optional): Override container entrypoint
70
ports (List[ContainerPort], optional): Exposed ports
71
environment_variables (List[EnvironmentVariable], optional): Environment variables
72
volume_mounts (List[VolumeMount], optional): Volume mount points
73
liveness_probe (ContainerProbe, optional): Health check configuration
74
readiness_probe (ContainerProbe, optional): Readiness check configuration
75
security_context (SecurityContextDefinition, optional): Security settings
76
77
Properties:
78
instance_view (ContainerPropertiesInstanceView): Runtime status (read-only)
79
80
Example:
81
container = Container(
82
name="api-server",
83
image="myregistry.azurecr.io/api:v1.2.3",
84
command=["python", "app.py", "--port=8080"],
85
resources=ResourceRequirements(
86
requests=ResourceRequests(memory_in_gb=2.0, cpu=1.5),
87
limits=ResourceLimits(memory_in_gb=4.0, cpu=2.0)
88
),
89
ports=[
90
ContainerPort(port=8080, protocol="TCP")
91
],
92
environment_variables=[
93
EnvironmentVariable(name="APP_ENV", value="production"),
94
EnvironmentVariable(name="DB_PASSWORD", secure_value="secret-password")
95
],
96
volume_mounts=[
97
VolumeMount(name="app-storage", mount_path="/data", read_only=False)
98
]
99
)
100
"""
101
```
102
103
## Resource Specifications
104
105
### ResourceRequirements { .api }
106
107
```python
108
class ResourceRequirements:
109
"""
110
CPU and memory resource specifications for containers.
111
112
Args:
113
requests (ResourceRequests): Minimum guaranteed resources
114
limits (ResourceLimits, optional): Maximum allowed resources
115
116
Example:
117
resources = ResourceRequirements(
118
requests=ResourceRequests(
119
memory_in_gb=1.0, # 1 GB minimum memory
120
cpu=0.5, # 0.5 CPU cores minimum
121
gpu=GpuResource(count=1, sku="K80") # Optional GPU
122
),
123
limits=ResourceLimits(
124
memory_in_gb=2.0, # 2 GB maximum memory
125
cpu=1.0 # 1 CPU core maximum
126
)
127
)
128
"""
129
130
class ResourceRequests:
131
"""
132
Minimum resource requirements for a container.
133
134
Args:
135
memory_in_gb (float): Memory in gigabytes (e.g., 0.5, 1.0, 2.0)
136
cpu (float): CPU cores (e.g., 0.1, 0.5, 1.0, 2.0)
137
gpu (GpuResource, optional): GPU resource specification
138
"""
139
140
class ResourceLimits:
141
"""
142
Maximum resource limits for a container.
143
144
Args:
145
memory_in_gb (float): Maximum memory in gigabytes
146
cpu (float): Maximum CPU cores
147
gpu (GpuResource, optional): Maximum GPU resources
148
"""
149
150
class GpuResource:
151
"""
152
GPU resource specification.
153
154
Args:
155
count (int): Number of GPU instances
156
sku (str): GPU SKU ("K80", "P100", "V100")
157
158
Example:
159
gpu = GpuResource(count=2, sku="V100")
160
"""
161
```
162
163
## Networking Models
164
165
### IpAddress { .api }
166
167
```python
168
class IpAddress:
169
"""
170
Public IP address configuration for container groups.
171
172
Args:
173
ports (List[ContainerPort]): Exposed ports and protocols
174
type (str): IP address type ("Public" or "Private")
175
ip (str, optional): Static IP address (for private IPs)
176
dns_name_label (str, optional): DNS label for FQDN generation
177
auto_generated_domain_name_label_scope (str, optional): Scope for auto DNS labels
178
dns_name_label_reuse_policy (str, optional): DNS label reuse policy
179
180
Properties:
181
fqdn (str): Fully qualified domain name (read-only)
182
183
Example:
184
# Public IP with custom DNS label
185
public_ip = IpAddress(
186
type="Public",
187
dns_name_label="my-app-instance",
188
ports=[
189
ContainerPort(port=80, protocol="TCP"),
190
ContainerPort(port=443, protocol="TCP")
191
]
192
)
193
194
# Private IP for VNet integration
195
private_ip = IpAddress(
196
type="Private",
197
ip="10.0.0.100",
198
ports=[ContainerPort(port=8080)]
199
)
200
"""
201
202
class ContainerPort:
203
"""
204
Port specification for containers and IP addresses.
205
206
Args:
207
port (int): Port number (1-65535)
208
protocol (str, optional): Protocol ("TCP" or "UDP", defaults to "TCP")
209
210
Example:
211
ports = [
212
ContainerPort(port=80, protocol="TCP"), # HTTP
213
ContainerPort(port=443, protocol="TCP"), # HTTPS
214
ContainerPort(port=53, protocol="UDP") # DNS
215
]
216
"""
217
218
class DnsConfiguration:
219
"""
220
Custom DNS configuration for container groups.
221
222
Args:
223
name_servers (List[str]): List of DNS server IP addresses
224
search_domains (List[str], optional): DNS search domains
225
options (str, optional): DNS resolver options
226
227
Example:
228
dns_config = DnsConfiguration(
229
name_servers=["8.8.8.8", "8.8.4.4"],
230
search_domains=["company.local"],
231
options="ndots:2 edns0"
232
)
233
"""
234
```
235
236
## Storage Models
237
238
### Volume { .api }
239
240
```python
241
class Volume:
242
"""
243
Storage volume that can be mounted in containers.
244
245
Args:
246
name (str): Volume name (unique within container group)
247
azure_file (AzureFileVolume, optional): Azure Files share
248
empty_dir (EmptyDirVolume, optional): Empty directory volume
249
secret (SecretVolume, optional): Secret-based volume
250
git_repo (GitRepoVolume, optional): Git repository volume
251
252
Note: Exactly one volume type must be specified.
253
254
Example:
255
# Azure Files volume
256
file_volume = Volume(
257
name="shared-storage",
258
azure_file=AzureFileVolume(
259
share_name="app-data",
260
storage_account_name="mystorageaccount",
261
storage_account_key="storage-key",
262
read_only=False
263
)
264
)
265
266
# Secret volume
267
secret_volume = Volume(
268
name="app-secrets",
269
secret=SecretVolume(
270
secret_name="ssl-certs",
271
default_mode=0o400
272
)
273
)
274
"""
275
276
class AzureFileVolume:
277
"""
278
Azure Files share volume configuration.
279
280
Args:
281
share_name (str): Name of the Azure Files share
282
storage_account_name (str): Storage account name
283
storage_account_key (str): Storage account access key
284
read_only (bool, optional): Mount as read-only (defaults to False)
285
"""
286
287
class VolumeMount:
288
"""
289
Volume mount configuration for containers.
290
291
Args:
292
name (str): Name of volume to mount (must match Volume.name)
293
mount_path (str): Path inside container where volume is mounted
294
read_only (bool, optional): Mount as read-only (defaults to False)
295
296
Example:
297
volume_mounts = [
298
VolumeMount(name="app-data", mount_path="/data", read_only=False),
299
VolumeMount(name="config", mount_path="/etc/app", read_only=True)
300
]
301
"""
302
303
class SecretVolume:
304
"""
305
Secret-based volume for sensitive data.
306
307
Args:
308
secret_name (str): Name of the secret
309
default_mode (int, optional): Default file permissions (octal)
310
items (Dict[str, str], optional): Key-to-filename mapping
311
"""
312
313
class GitRepoVolume:
314
"""
315
Git repository volume for code deployment.
316
317
Args:
318
repository (str): Git repository URL
319
directory (str, optional): Target directory name
320
revision (str, optional): Git revision (branch, tag, or commit)
321
"""
322
```
323
324
## Configuration Models
325
326
### EnvironmentVariable { .api }
327
328
```python
329
class EnvironmentVariable:
330
"""
331
Environment variable configuration for containers.
332
333
Args:
334
name (str): Environment variable name
335
value (str, optional): Plain text value
336
secure_value (str, optional): Encrypted/secure value
337
338
Note: Specify either 'value' or 'secure_value', not both.
339
340
Example:
341
env_vars = [
342
EnvironmentVariable(name="APP_PORT", value="8080"),
343
EnvironmentVariable(name="DEBUG", value="false"),
344
EnvironmentVariable(name="API_KEY", secure_value="secret-api-key"),
345
EnvironmentVariable(name="DB_CONNECTION", secure_value="connection-string")
346
]
347
"""
348
349
class ImageRegistryCredential:
350
"""
351
Container registry authentication credentials.
352
353
Args:
354
server (str): Registry server hostname
355
username (str, optional): Registry username
356
password (str, optional): Registry password
357
identity (str, optional): Managed identity resource ID for authentication
358
identity_url (str, optional): Identity endpoint URL
359
360
Example:
361
# Username/password authentication
362
registry_cred = ImageRegistryCredential(
363
server="myregistry.azurecr.io",
364
username="registry-user",
365
password="registry-password"
366
)
367
368
# Managed identity authentication
369
managed_identity_cred = ImageRegistryCredential(
370
server="myregistry.azurecr.io",
371
identity="/subscriptions/sub-id/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity"
372
)
373
"""
374
```
375
376
## Health Check Models
377
378
### ContainerProbe { .api }
379
380
```python
381
class ContainerProbe:
382
"""
383
Health check probe configuration for containers.
384
385
Args:
386
exec_probe (ContainerExec, optional): Command-based probe
387
http_get (ContainerHttpGet, optional): HTTP-based probe
388
initial_delay_seconds (int, optional): Delay before first probe
389
period_seconds (int, optional): Probe interval
390
failure_threshold (int, optional): Failures before marking unhealthy
391
success_threshold (int, optional): Successes before marking healthy
392
timeout_seconds (int, optional): Probe timeout
393
394
Example:
395
# HTTP health check
396
liveness_probe = ContainerProbe(
397
http_get=ContainerHttpGet(
398
path="/health",
399
port=8080,
400
scheme="HTTP"
401
),
402
initial_delay_seconds=30,
403
period_seconds=10,
404
failure_threshold=3
405
)
406
407
# Command-based health check
408
readiness_probe = ContainerProbe(
409
exec_probe=ContainerExec(
410
command=["curl", "-f", "http://localhost:8080/ready"]
411
),
412
initial_delay_seconds=5,
413
period_seconds=5
414
)
415
"""
416
417
class ContainerHttpGet:
418
"""
419
HTTP-based health check configuration.
420
421
Args:
422
path (str, optional): HTTP request path
423
port (int): Port number for health check
424
scheme (str, optional): HTTP scheme ("HTTP" or "HTTPS")
425
http_headers (List[HttpHeader], optional): Custom HTTP headers
426
"""
427
428
class ContainerExec:
429
"""
430
Command-based health check configuration.
431
432
Args:
433
command (List[str]): Command and arguments to execute
434
"""
435
436
class HttpHeader:
437
"""
438
HTTP header for health check requests.
439
440
Args:
441
name (str): Header name
442
value (str): Header value
443
"""
444
```
445
446
## Security Models
447
448
### ContainerGroupIdentity { .api }
449
450
```python
451
class ContainerGroupIdentity:
452
"""
453
Managed identity configuration for container groups.
454
455
Args:
456
type (str): Identity type ("SystemAssigned", "UserAssigned", "SystemAssigned,UserAssigned", "None")
457
user_assigned_identities (Dict[str, UserAssignedIdentity], optional): User-assigned identities
458
459
Properties:
460
principal_id (str): System-assigned identity principal ID (read-only)
461
tenant_id (str): System-assigned identity tenant ID (read-only)
462
463
Example:
464
# System-assigned identity
465
system_identity = ContainerGroupIdentity(type="SystemAssigned")
466
467
# User-assigned identity
468
user_identity = ContainerGroupIdentity(
469
type="UserAssigned",
470
user_assigned_identities={
471
"/subscriptions/sub-id/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-identity":
472
UserAssignedIdentity()
473
}
474
)
475
"""
476
```
477
478
## Response Models
479
480
### ContainerExecRequest { .api }
481
482
```python
483
class ContainerExecRequest:
484
"""
485
Request configuration for container command execution.
486
487
Args:
488
command (List[str]): Command and arguments to execute
489
terminal_size (ContainerExecRequestTerminalSize, optional): Terminal dimensions
490
491
Example:
492
# Simple command execution
493
exec_request = ContainerExecRequest(
494
command=["ls", "-la", "/app"]
495
)
496
497
# Interactive shell with terminal size
498
shell_request = ContainerExecRequest(
499
command=["/bin/bash"],
500
terminal_size=ContainerExecRequestTerminalSize(rows=24, cols=80)
501
)
502
"""
503
504
class ContainerExecRequestTerminalSize:
505
"""
506
Terminal size specification for interactive command execution.
507
508
Args:
509
rows (int): Number of terminal rows
510
cols (int): Number of terminal columns
511
"""
512
513
class ContainerExecResponse:
514
"""
515
Response from container command execution.
516
517
Properties:
518
web_socket_uri (str): WebSocket URI for command interaction
519
password (str): Authentication password for WebSocket connection
520
"""
521
522
class ContainerAttachResponse:
523
"""
524
Response from container attachment operation.
525
526
Properties:
527
web_socket_uri (str): WebSocket URI for container attachment
528
password (str): Authentication password for WebSocket connection
529
"""
530
531
class Logs:
532
"""
533
Container logs response.
534
535
Properties:
536
content (str): Log content as text
537
"""
538
```
539
540
## Complete Usage Example
541
542
```python
543
from azure.mgmt.containerinstance.models import (
544
ContainerGroup, Container, ContainerGroupProperties,
545
ResourceRequirements, ResourceRequests, ResourceLimits,
546
IpAddress, ContainerPort, EnvironmentVariable,
547
Volume, VolumeMount, AzureFileVolume,
548
ImageRegistryCredential, ContainerProbe, ContainerHttpGet,
549
ContainerGroupIdentity
550
)
551
552
# Complete container group with all features
553
container_group = ContainerGroup(
554
location="East US",
555
containers=[
556
Container(
557
name="web-app",
558
image="myregistry.azurecr.io/webapp:v2.1.0",
559
resources=ResourceRequirements(
560
requests=ResourceRequests(memory_in_gb=2.0, cpu=1.0),
561
limits=ResourceLimits(memory_in_gb=4.0, cpu=2.0)
562
),
563
ports=[ContainerPort(port=80), ContainerPort(port=443)],
564
environment_variables=[
565
EnvironmentVariable(name="ASPNETCORE_ENVIRONMENT", value="Production"),
566
EnvironmentVariable(name="ConnectionStrings__Default", secure_value="connection-string")
567
],
568
volume_mounts=[
569
VolumeMount(name="app-data", mount_path="/data"),
570
VolumeMount(name="logs", mount_path="/logs")
571
],
572
liveness_probe=ContainerProbe(
573
http_get=ContainerHttpGet(path="/health", port=80),
574
initial_delay_seconds=30,
575
period_seconds=10
576
)
577
)
578
],
579
os_type="Linux",
580
restart_policy="Always",
581
ip_address=IpAddress(
582
type="Public",
583
dns_name_label="my-production-app",
584
ports=[ContainerPort(port=80), ContainerPort(port=443)]
585
),
586
volumes=[
587
Volume(
588
name="app-data",
589
azure_file=AzureFileVolume(
590
share_name="appdata",
591
storage_account_name="mystorageaccount",
592
storage_account_key="storage-key"
593
)
594
),
595
Volume(
596
name="logs",
597
azure_file=AzureFileVolume(
598
share_name="logs",
599
storage_account_name="mystorageaccount",
600
storage_account_key="storage-key"
601
)
602
)
603
],
604
image_registry_credentials=[
605
ImageRegistryCredential(
606
server="myregistry.azurecr.io",
607
username="registry-user",
608
password="registry-password"
609
)
610
],
611
identity=ContainerGroupIdentity(type="SystemAssigned"),
612
tags={
613
"environment": "production",
614
"application": "web-app",
615
"version": "v2.1.0"
616
}
617
)
618
```