Azure Container Instances
Azure Container Instances (ACI) provides a local Azure Resource Manager (ARM) control plane for container groups. It lets clients create one group resource, inspect its state, run group actions, and read container logs without a live Azure subscription. The handler can either model the group in memory or connect it to Docker resources for local execution. For the wider service map, see Azure compute and container services; for the related managed container platform, see Azure Container Apps and storage backends.
System role
ACI uses a container group as its unit of deployment. The group combines one or more containers with shared runtime, network, volume, and restart settings, while the ARM boundary presents that group as one resource.
ARM request boundary
The handler serves the Microsoft.ContainerInstance provider. Clients can create, read, list, update, delete, start, stop, and restart groups. They can also request logs and common location or operation data used by Azure tools.
| Request area | Purpose |
|---|---|
| Container groups | Create, replace, read, list, tag-update, and delete groups |
| Group actions | Start, stop, or restart a group |
| Container sub-resources | Read logs; report unsupported interactive access |
| Location data | Return empty cached-image, capability, and usage results |
| Operation status | Report the result of an asynchronous action |
References: src/…/AciHandler.java• L46-77 src/…/AciHandler.java• L217-293
Resource model
An ACI resource is a ContainerGroup. Its identity is the combination of subscription, resource group, and group name. That identity drives the ARM resource ID, storage lookup, list scope, and resource-group discovery.
Container group state
The group stores the client’s container and group settings together with emulator-managed location, tags, creation time, and provisioning state. Its response also exposes a runtime view that describes the group and each container.
| Model part | Role |
|---|---|
| Identity | Subscription, resource group, and name define the ARM resource |
| Deployment state | provisioningState describes whether the group is being created, ready, or failed |
| Container definition | Image, command, ports, environment values, and resource requests define each container |
| Group settings | Operating system, restart policy, SKU, volumes, diagnostics, and registry data apply to the group |
| Runtime view | Group and container state show what the local runtime reports |
| Network view | IP type, ports, address, and optional DNS label describe the group endpoint |
References: src/…/AciHandler.java• L298-323 src/…/AciHandler.java• L568-603 src/…/AciContainerGroupManager.java• L269-319
Resource identity
The ARM path is stable for a group name within its subscription and resource group. The handler uses the same identity when it scopes reads and lists, contributes the group to the shared resource index, and removes it.
References: src/…/AciHandler.java• L309-320 src/…/AciHandler.java• L399-415 src/…/AciHandler.java• L809-830
Container group lifecycle
The lifecycle has a mocked mode and a container-backed mode. Mocked mode completes the ARM resource with synthetic runtime data. Container-backed mode creates local Docker resources and updates the ARM record from their observed state.
This diagram shows how a group request becomes an ARM resource and, when enabled, a set of local runtime resources.
flowchart LR
A[PUT container group] --> B[Validate container data]
B -->|invalid| C[Return ARM error]
B -->|valid| D[Apply defaults]
D --> E[Store group]
E --> F{Container-backed mode?}
F -->|no| G[Return synthetic runtime view]
F -->|yes| H[Create local containers]
H -->|success| I[Observe runtime state]
H -->|failure| J[Clean up and mark failed]
G --> K[GET, list, logs, or action]
I --> K
J --> K
Creation and replacement
PUT requires at least one container and an image for each container. The handler fills omitted service defaults before it stores the group, then returns 201 for a new group or 200 for a replacement.
In mocked mode, creation completes at once. In container-backed mode, the group starts in Creating while local containers start. The first container owns the group network identity and published ports. Other containers join its network namespace when it is running, so group members can use shared localhost behavior. A readiness check changes the state to Succeeded after every container has started, even when a container has already ended. If the container definition changes, the handler replaces the old local resources. If local startup fails, it removes partial resources and marks the group Failed.
References: src/…/AciHandler.java• L298-368 src/…/AciHandler.java• L680-717 src/…/AciContainerGroupManager.java• L81-117 src/…/AciContainerGroupManager.java• L128-180 src/…/AciContainerGroupManager.java• L269-313
Query and listing
A single-group GET returns the full resource and its instance view. Subscription and resource-group list calls return the group collection without instance views. An unknown group returns an ARM not-found error.
In container-backed mode, the instance view uses current local container state. On service start, persisted groups with missing local containers are relaunched when they were creating or succeeded. A group that previously failed is not started again automatically.
References: src/…/AciHandler.java• L371-375 src/…/AciHandler.java• L418-425 src/…/AciHandler.java• L157-187 src/…/AciContainerGroupManager.java• L281-319
Tag updates and deletion
PATCH changes tags without changing the container definition. DELETE removes the group and returns its last resource body when it exists. A repeated delete returns 204, so cleanup is safe to repeat.
In container-backed mode, deletion also removes the local containers, named volumes, and related resources. The handler builds the response before cleanup so the body still describes the resource that the client deleted.
References: src/…/AciHandler.java• L377-416 src/…/AciContainerGroupManager.java• L407-419
Container operations
Group actions extend the resource model after deployment. Mocked mode accepts the actions as control-plane operations. Container-backed mode applies them to local containers and records whether the requested state was reached.
Group actions
start returns 202 with an operation URL. restart returns 204 with an operation URL. stop returns a synchronous 204 without an operation URL. Clients can query the operation URL for Succeeded or Failed; unknown operation IDs return 404.
The action order preserves the group’s shared network behavior. Starting brings up the primary container before its members, while stopping takes members down before the primary. Restarting bounces the primary first and then its members so they rejoin its new network namespace. The manager checks the state reached by the containers after each action. If local container records are missing, a start can recreate the group resources.
References: src/…/AciHandler.java• L428-459 src/…/AciHandler.java• L758-795 src/…/AciContainerGroupManager.java• L352-405
Logs and interactive access
The logs endpoint first checks the group and the named container. Mocked mode returns an empty content envelope because no local log stream exists. Container-backed mode reads logs from the local container and accepts tail and timestamp query options.
Interactive exec and attach are not available in the local emulator. Those requests return 501 NotImplemented instead of claiming that an interactive session exists.
References: src/…/AciHandler.java• L260-267 src/…/AciHandler.java• L461-483 src/…/AciContainerGroupManager.java• L321-325
ARM response behavior
The handler shapes responses for ARM clients that expect stable nested fields and Azure-style runtime values. It adds defaults and runtime data on read while hiding values that are write-only.
Defaults and runtime views
The service supplies defaults for operating system, restart policy, SKU, container ports, and resource requests when the request omits them. It also normalizes enum values to the casing used in ARM responses. A requested DNS label produces a location-based FQDN, and the response reports a synthetic or local endpoint.
Container and group instance views use synthetic Running state in mocked mode. In container-backed mode, they map local runtime states to Azure states such as Running, Waiting, and Terminated. Completed groups report Succeeded or Failed from container exit results when the restart policy allows termination. The reported group address follows the local endpoint mode and the ports that the manager publishes.
References: src/…/AciHandler.java• L485-564 src/…/AciHandler.java• L568-677 src/…/AciContainerGroupManager.java• L327-350 src/…/AciContainerGroupManager.java• L438-450
Secret masking
The service keeps secret values for local runtime use but removes them from ARM responses. Secure environment values, registry passwords, and secret-volume contents are hidden. Plain environment values remain visible.
References: src/…/AciHandler.java• L720-756
Service scope
ACI is a local ARM service that models the control-plane contract and can optionally run containers. It supports the common group lifecycle but does not claim to provide every Azure Container Instances feature.
Supported and unsupported data
The service supports empty-directory and secret volume concepts. It rejects Azure File and Git repository volumes because the local runtime cannot provide those mounts. In container-backed mode, empty-directory volumes become group-scoped local volumes, while secret volumes receive their file content before the container starts. Location catalogs and outbound network dependency queries return empty results so clients can complete discovery without seeing unsupported capabilities.
References: src/…/AciHandler.java• L242-245 src/…/AciHandler.java• L269-274 src/…/AciHandler.java• L487-508 src/…/AciContainerGroupManager.java• L184-228
State reset
The administrative reset clears all stored groups. In container-backed mode, it first removes their local containers and related resources, then clears the ARM records. This returns the service to an empty state for a new local lifecycle.
References: src/…/AciHandler.java• L916-933
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the provider routes, resource identity, list scopes, and resource index entry aligned when the group boundary changes.
- Keep PUT status codes and action
Locationbehavior aligned with ARM client pollers. - Keep recorded operation outcomes tied to operation IDs. Unknown or evicted IDs must not appear successful.
- Preserve response masking for secure environment values, registry passwords, and secret volumes.
- Keep response defaults and canonical enum values aligned with the resource shape expected by ARM clients.
- Keep ARM records aligned with local containers during creation, replacement, restart, startup recovery, deletion, shutdown, and reset.
- Keep readiness based on every container having started. Do not require all containers to remain running.
- Keep primary-container network ownership, member start order, port allocation, and reported endpoint behavior aligned.
- Release allocated ports and local volumes when a group fails or is deleted so later groups can use them.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A group has no containers or a container has no image | The request fails with 400 InvalidRequestContent | Validate the group before saving it |
| A request uses an Azure File or Git repository volume | The local runtime cannot honor the group | Reject unsupported volume types |
| Required nested defaults are missing from a response | ARM clients can fail to read or flatten the resource | Add service defaults before response creation |
| A response includes a secret value | Secret data leaves the emulator and can cause client state drift | Sanitize secure values on every ARM response |
| Local startup fails after partial resource creation | Orphaned resources can block later groups | Remove partial resources and mark the group Failed |
| A published port is already reserved or cannot bind on the Docker host | The group cannot start with its advertised endpoint | Reserve ports before launch and release them on rollback |
| A primary container is absent or stopped when members start | Members cannot share the group network namespace | Start the primary first and use a fallback network only when it has ended |
| Persisted records point to missing local containers | Later reads or actions report stale runtime state | Reconcile eligible groups at startup and recreate them for start |
| An action operation ID is unknown or evicted | A client can treat an untracked action as successful | Return 404 for missing outcomes |
A client calls exec or attach | No interactive session is available | Return 501 NotImplemented |
Key files
| File | Why to read it |
|---|---|
| src/…/AciHandler.java | Defines the ARM boundary, group lifecycle, action responses, runtime views, recovery, and reset behavior |
| src/…/AciArmSurface.java | Defines the provider boundary, location scope, and group-name rules |
| src/…/AciContainerGroupManager.java | Explains the optional container-backed lifecycle, shared group networking, ports, volumes, runtime state, and cleanup |
| src/…/AciModels.java | Defines the container-group resource shape and ARM identity views |
| src/…/AciHandlerTest.java | Shows the client-facing lifecycle, response contracts, validation limits, and reset behavior |