Azure Container Apps
Azure Container Apps provides a local model of the Azure Container Apps control plane and data plane. It lets an engineer create managed environments and container apps through ARM requests, turn app templates into local revisions, and send ingress traffic to running local containers.
Service boundaries
The service has two linked paths. The management path stores Azure-shaped resources and controls revisions. The data path selects an active revision and forwards an HTTP request to one of its local replicas. The broader service family is described in Azure compute services, while the single-container alternative is described in Azure Container Instances.
The main flow is:
flowchart LR
A[ARM request] --> B[Container Apps handler]
B --> C[Environment and app state]
B --> D[Revision state]
D --> E[Local runtime manager]
E --> F[Container replicas]
G[Ingress request] --> B
B --> H[Traffic selection]
H --> I[Ingress proxy]
I --> F
Resource model
The resource model follows the Azure Container Apps hierarchy. A managed environment supplies the domain and ownership boundary for container apps. Each app stores its submitted document and a history of revisions created from its template.
Managed environments
A managed environment is the parent resource for local apps. The service keeps its Azure resource identity and document, then adds a stable default domain that app and revision addresses use. An environment cannot be removed while an app still refers to it.
The environment response presents Azure-style status and network fields. It does not return write-only monitoring or logging secret values. Environment collections can be queried at subscription scope or resource-group scope.
References: src/…/ContainerAppsHandler.java• L168-253 src/…/ContainerAppsHandler.java• L658-683 src/…/ContainerAppsModels.java• L15-48
Container apps
A container app is the durable service definition under a managed environment. Its document describes the container template, scale limits, secrets, revision mode, and optional ingress. The handler validates the environment link, requires at least one container image, and checks scale and ingress values before it accepts the app.
The app response adds the current provisioning and running state, the latest revision details, and the app ingress name. Secret values stay hidden in normal app responses. A separate secret query returns the configured secret objects for clients that need the management-plane view.
References: src/…/ContainerAppsHandler.java• L269-382 src/…/ContainerAppsHandler.java• L685-717 src/…/ContainerAppsHandler.java• L448-459 src/…/ContainerAppsModels.java• L50-92
Revisions
A revision is an immutable app template instance with its own name, status, replica count, and fully qualified domain name. A new revision is created when an app is first created or when its template changes. An explicit revision suffix controls its name. Otherwise the app assigns a sequential suffix.
Revision mode controls how active revisions coexist:
| Mode | Active revision behavior |
|---|---|
Single | A new or activated revision stops other active revisions. |
Multiple | Active revisions can run together and receive configured traffic weights. |
Revision actions expose activation, deactivation, and restart behavior. The app reports a failed revision without hiding an older ready revision, so a failed replacement does not remove the last usable version.
References: src/…/ContainerAppsHandler.java• L286-314 src/…/ContainerAppsHandler.java• L403-437 src/…/ContainerAppsHandler.java• L485-569 src/…/ContainerAppsModels.java• L94-142
ARM management plane
The ARM handler is the entry point for the Azure management contract. The src/…/ContainerAppsArmSurface.java resource surface registers the Microsoft.App resource types that the handler serves. The handler then maps those paths to environment, app, secret, and revision operations, stores the resulting state, and contributes environments and apps to the resource-group index.
ARM resource surface
The ARM resource surface defines the public resource families for this service. It exposes resource-group-scoped container apps and managed environments, plus child resources for app revisions and environment storage. Parent resources require a location. Child resource types inherit their parent identity. Container app names follow the service's lowercase name rule.
References: src/…/ContainerAppsArmSurface.java• L14-40
Resource operations
The handler supports environment and app create, read, update, list, and delete operations where the Azure contract needs them. Updates can merge a partial document into an existing resource. The handler also supports name checks, empty environment storage lists, revision queries, revision actions, and secret listing.
When a request creates or updates an app, the handler validates its parent and template before it changes revision state. When a request deletes an app, it stops its local runtime first. When the service clears its state or shuts down, it stops all managed runtimes and clears stored state as required by the service lifecycle.
References: src/…/ContainerAppsHandler.java• L107-165 src/…/ContainerAppsHandler.java• L168-314 src/…/ContainerAppsHandler.java• L950-961
Revision creation flow
Revision creation joins the management document to the local runtime. The handler copies the app template into revision state, builds a revision address from the environment domain, starts the requested local replicas when runtime execution is enabled, and then records the resulting status.
The sequence is:
- Accept an app create or template update.
- Validate the environment, containers, scale range, and ingress settings.
- Create a named revision from the new template.
- Start local replicas unless mocked mode is enabled.
- Mark the revision ready or failed.
- Apply
Single-mode deactivation rules.
In mocked mode, the management plane still creates and reports revision state. The data plane returns a clear unavailable response instead of starting local containers.
References: src/…/ContainerAppsHandler.java• L286-437
Local runtime
The runtime manager turns a revision into local container replicas. It keeps the runtime handles separate from durable ARM state, so management responses remain available while the manager controls start, stop, readiness, endpoint choice, and cleanup.
Replica assembly
Each replica starts the containers in the revision template. The first container owns the replica network namespace and ingress port. Additional containers join that namespace, which gives a multi-container revision one local network identity and one ingress endpoint.
Starting a revision first removes any runtime already held for that revision. If a later container or replica fails to start, the manager removes the containers that it already started instead of leaving a partial replica set.
Environment variables can use app secrets. Before it starts a container, the manager resolves inline secret values and supported Key Vault references against the emulator's own vault. A Key Vault reference can use an Azure cloud vault URL or the local account URL form, and can name a specific version. The identity field is accepted but is not checked by the local data plane. An unresolved secret is omitted from the runtime secret set, so an environment variable that refers to it rejects replica startup. The manager labels running containers by service and managed environment so it can recognize local runtimes after a restart, including replicas created by an earlier service-label form.
References: src/…/ContainerAppRuntimeManager.java• L50-85 src/…/ContainerAppRuntimeManager.java• L119-185 src/…/ContainerAppRuntimeManager.java• L226-284 src/…/KeyVaultSecretReference.java• L12-57
Readiness and endpoints
The runtime manager waits for each ingress endpoint to accept a network connection before it marks the replica ready. It selects reachable replicas in round-robin order and skips replicas that no longer respond. If startup fails, it removes the containers that it already started.
The manager also checks whether a caller belongs to the managed environment. It uses the addresses of current or labeled local containers. This allows internal ingress authorization to survive a manager restart without opening private apps to public callers.
References: src/…/ContainerAppRuntimeManager.java• L86-121 src/…/ContainerAppRuntimeManagerTest.java• L86-123
Ingress data plane
Ingress requests use the app's public name rather than an ARM resource path. The handler resolves that name within the environment domain, selects an active revision, verifies access, obtains a reachable local endpoint, and passes the request to the proxy.
Host and traffic routing
An app ingress name is formed from the app name and its managed environment domain. An app without ingress has no data-plane endpoint. An app with no active revision returns an unavailable response.
Traffic rules can name a revision or refer to the latest active revision. Positive weights select revisions in a deterministic counter-based cycle whose proportions match the configured weights. Without usable traffic rules, the latest active revision is the fallback.
External ingress accepts public callers. Internal ingress requires the caller address to match a running container in the same managed environment. The service performs this access check before it starts a stopped or restored runtime.
References: src/…/ContainerAppsHandler.java• L571-625 src/…/ContainerAppsHandler.java• L627-656 src/…/ContainerAppsHandlerUnitTest.java• L115-166
Request forwarding
The ingress proxy sends the original method, body, headers, path, and query parameters to the selected local endpoint. It encodes query names and values, preserves the raw path, and removes hop-by-hop headers so the local container receives an HTTP request with the right application content. Ingress can select HTTP/2 for the backend transport; the default backend transport is HTTP/1.1.
The proxy copies the backend status, body, and end-to-end response headers back to the caller. Connection failure or proxy timeout becomes a 502 ContainerAppUnavailable response. This keeps local container errors at the data-plane boundary rather than changing the ARM resource state.
References: src/…/ContainerAppIngressProxy.java• L22-43 src/…/ContainerAppIngressProxy.java• L45-80 src/…/ContainerAppIngressProxy.java• L82-102 src/…/ContainerAppIngressProxyTest.java• L23-52
State and lifecycle
Container Apps separates durable resource state from live container state. The handler stores environments and apps in the Container Apps storage area. The runtime manager keeps live replica handles in memory and reconstructs internal-caller checks from labeled running containers when needed.
This split explains an important behavior: an app can be read through ARM after a service restart even when its live endpoint is not currently available. A later authorized ingress request can start a revision from zero when its scale policy permits it. Deleting an app or stopping the service removes its live replicas so local containers do not outlive their owning resource.
References: src/…/ContainerAppsHandler.java• L57-68 src/…/ContainerAppsHandler.java• L571-620 src/…/ContainerAppsHandler.java• L950-961 src/…/ContainerAppRuntimeManager.java• L69-121
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the ARM resource identity, storage key, environment link, and ingress domain rules aligned. A mismatch can make a resource readable but unreachable through its expected host.
- Keep revision status transitions aligned with runtime start and stop actions. A revision must not report ready when its endpoint is absent or report stopped while its replicas remain live.
- Keep traffic weights, active-revision mode, and revision action behavior consistent. Changes in one contract can silently route requests to an inactive revision.
- Keep secret masking in app and environment responses separate from secret expansion at runtime. Keep Key Vault URL parsing aligned with the vault URL forms used by the Key Vault service. Management responses must not expose values that the runtime still needs.
- Keep internal caller checks tied to the same normalized environment identity and container labels used during replica creation. Preserve compatibility with older service labels when changing runtime discovery.
- Keep encoded ingress paths and query values intact across the request boundary. Proxy changes can alter application routing without changing the ARM state.
- Keep the ARM resource surface aligned with handler routes. Adding or removing a resource family changes which
Microsoft.Apppaths the ARM layer can resolve.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An app points to a missing managed environment. | The app is rejected with ManagedEnvironmentNotFound. | Validate the environment resource before revision creation. |
| A template has no container or has a missing image or name. | The app or local revision cannot start. | Require at least one complete container entry. |
| A scale range has an invalid minimum or maximum. | The app is rejected with InvalidScaleRule. | Enforce 0 <= minReplicas <= maxReplicas and a positive maximum. |
| Ingress traffic weights do not total 100. | The app is rejected and no new routing state is accepted. | Validate every weight and the total before saving the app. |
| A revision cannot reach its target port before the timeout. | The revision becomes failed and its started containers are removed. | Wait for readiness and clean up partial startup. |
A secretRef names a missing secret or an unresolved Key Vault reference. | Replica startup fails before the container receives its environment. | Resolve inline and Key Vault-backed secrets before starting the replica. |
| A Key Vault URL does not use a supported cloud or local account form. | The reference cannot resolve and any dependent replica fails to start. | Parse only recognized vault hosts and secrets/{name}[/{version}] paths. |
| A private ingress request comes from outside the managed environment. | The host is treated as not found. | Check the caller before starting a restored or scaled-from-zero runtime. |
| No active revision has a reachable endpoint. | Ingress returns 503 ContainerAppUnavailable. | Select only active revisions and probe endpoints before proxying. |
| An environment is deleted while an app still uses it. | The delete returns 409 ManagedEnvironmentInUse. | Remove dependent apps before removing the environment. |
Key files
| File | Why to read it |
|---|---|
| src/…/ContainerAppsHandler.java | Primary ARM and ingress coordinator. It shows how resources, revisions, routing, and lifecycle actions connect. |
| src/…/ContainerAppsArmSurface.java | Defines the Microsoft.App resource families and the parent or child boundaries exposed to ARM. |
| src/…/ContainerAppsModels.java | Defines the durable environment, app, and revision concepts used by the service. |
| src/…/ContainerAppRuntimeManager.java | Shows how revision templates become local replicas and how endpoints, secrets, and internal callers are managed. |
| src/…/KeyVaultSecretReference.java | Defines the supported Azure and local Key Vault URL forms used when a revision resolves secrets. |
| src/…/ContainerAppIngressProxy.java | Shows the boundary between an ingress request and a local container endpoint. |
| src/…/ContainerAppsHandlerTest.java | Verifies the end-to-end ARM contract, revision modes, ingress outcomes, and resource relationships. |
| src/…/ContainerAppsHandlerUnitTest.java | Covers routing proportions, failed replacement behavior, and private-ingress authorization. |
| src/…/ContainerAppRuntimeManagerTest.java | Verifies replica networking, endpoint selection, readiness reachability, and restart-safe caller checks. |
| src/…/ContainerAppIngressProxyTest.java | Verifies that encoded request paths reach the local revision without corruption. |