หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
A container app has access to different types of storage. A single app can take advantage of more than one type of storage if necessary.
Note
Avoid using special characters in volume names to prevent deployment failures. For example, a volume named credentials.json contains a special character (.) which results in a deployment error.
| Storage type | Description | Persistence | Usage example |
|---|---|---|---|
| Container-scoped storage | Ephemeral storage available to a running container | Data is available until container shuts down | Writing a local app cache. |
| Replica-scoped storage | Ephemeral storage for sharing files between containers in the same replica | Data is available until replica shuts down | The main app container writing log files that a sidecar container processes. |
| Azure Files | Permanent storage | Data is persisted to Azure Files | Writing files to a file share to make data accessible by other systems. |
Note
Azure Container Apps doesn't support mounting file shares from Azure NetApp Files or Azure Blob Storage.
Ephemeral storage
A container app can read and write temporary data to ephemeral storage. Ephemeral storage can be scoped to a container or a replica. The total amount of container-scoped and replica-scoped storage available to each replica depends on the total number of vCPUs allocated to the replica.
| vCPUs | Total ephemeral storage |
|---|---|
| 0.25 or lower | 1 GiB |
| 0.5 or lower | 2 GiB |
| 1 or lower | 4 GiB |
| Over 1 | 8 GiB |
Container-scoped storage
A container can write to its own file system.
Container file system storage has the following characteristics:
- The storage is temporary and disappears when the container shuts down or restarts.
- Only processes running in the current container can see files written to this storage.
Replica-scoped storage
You can mount an ephemeral, temporary volume that's equivalent to EmptyDir (empty directory) in Kubernetes. This storage is scoped to a single replica. Use an EmptyDir volume to share data between containers in the same replica.
Replica-scoped storage has the following characteristics:
- Files persist for the lifetime of the replica.
- If a container in a replica restarts, the files in the volume remain.
- Any init or app containers in the replica can mount the same volume.
- A container can mount multiple
EmptyDirvolumes.
To configure replica-scoped storage, first define an EmptyDir volume in the revision. Then define a volume mount in one or more containers in the revision.
Prerequisites
| Requirement | Instructions |
|---|---|
| Azure account | If you don't have one, create an account for free. |
| Azure Container Apps environment | Create a container apps environment. |
Configuration
When you configure replica-scoped storage by using the Azure CLI, you must use a YAML definition to create or update your container app.
To update an existing container app to use replica-scoped storage, export your app's specification to a YAML file named app.yaml.
az containerapp show -n <APP_NAME> -g <RESOURCE_GROUP_NAME> -o yaml > app.yamlMake the following changes to your container app specification.
- Add a
volumesarray to thetemplatesection of your container app definition and define a volume. If you already have avolumesarray, add a new volume to the array.- The
nameis an identifier for the volume. - Use
EmptyDiras thestorageType.
- The
- For each container in the template that you want to mount the volume, define a volume mount in the
volumeMountsarray of the container definition.- The
volumeNameis the name defined in thevolumesarray. - The
mountPathis the path in the container to mount the volume.
- The
properties: managedEnvironmentId: /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME>/providers/Microsoft.App/managedEnvironments/<ENVIRONMENT_NAME> configuration: activeRevisionsMode: Single template: containers: - image: <IMAGE_NAME1> name: my-container-1 volumeMounts: - mountPath: /myempty volumeName: myempty - image: <IMAGE_NAME_2> name: my-container-2 volumeMounts: - mountPath: /myempty volumeName: myempty volumes: - name: myempty storageType: EmptyDir- Add a
Update your container app by using the YAML file.
az containerapp update --name <APP_NAME> --resource-group <RESOURCE_GROUP_NAME> \ --yaml app.yaml
For a full example, see the YAML specification.
To create a replica-scoped volume and mount it in a container, make the following changes to the container apps resource in an ARM template:
- Add a
volumesarray to thetemplatesection of your container app definition and define a volume. If you already have avolumesarray, add a new volume to the array.- The
nameis an identifier for the volume. - Use
EmptyDiras thestorageType.
- The
- For each container in the template that you want to mount the volume, define a volume mount in the
volumeMountsarray of the container definition.- The
volumeNameis the name defined in thevolumesarray. - The
mountPathis the path in the container to mount the volume.
- The
Example ARM template snippet:
{
"apiVersion": "2022-03-01",
"type": "Microsoft.App/containerApps",
"name": "[parameters('containerappName')]",
"location": "[parameters('location')]",
"properties": {
...
"template": {
"revisionSuffix": "myrevision",
"containers": [
{
"name": "main",
"image": "[parameters('container_image')]",
"resources": {
"cpu": 0.5,
"memory": "1Gi"
},
"volumeMounts": [
{
"mountPath": "/myempty",
"volumeName": "myempty"
}
]
},
{
"name": "sidecar",
"image": "[parameters('sidecar_image')]",
"resources": {
"cpu": 0.5,
"memory": "1Gi"
},
"volumeMounts": [
{
"mountPath": "/myempty",
"volumeName": "myempty"
}
]
}
],
"scale": {
"minReplicas": 1,
"maxReplicas": 3
},
"volumes": [
{
"name": "myempty",
"storageType": "EmptyDir"
}
]
}
}
}
See the ARM template API specification for a full example.
To create a replica-scoped volume and mount it in a container, deploy a new revision of your container app by using the Azure portal.
In the Azure portal, go to your container app.
Select Revision management in the left menu.
Select Create new revision.
Select the container where you want to mount the volume.
In the Edit a container context pane, select the Volume mounts tab.
Under the Ephemeral storage section, create a new volume with the following information:
- Volume name: A name for the ephemeral volume.
- Mount path: The absolute path in the container to mount the volume.
Select Save to save changes and exit the context pane.
Select Create to create the new revision.
Azure Files volume
You can mount a file share from Azure Files as a volume in a container.
Important
Azure Container Apps supports only classic Azure file shares, which are created within a storage account (the Microsoft.Storage/storageAccounts/fileServices/shares resource type). Container Apps doesn't support the newer Microsoft.FileShares top-level resource type. If you try to mount a Microsoft.FileShares resource, the operation fails. To create a supported file share, see Create a classic Azure file share.
Azure Files storage has the following characteristics:
- Files written under the mount location are persisted to the file share.
- Files in the share are available via the mount location.
- Multiple containers can mount the same file share, including ones that are in another replica, revision, or container app.
- All containers that mount the share can access files written by any other container or method.
- More than one Azure Files volume can be mounted in a single container.
Azure Files supports both SMB (Server Message Block) and NFS (Network File System) protocols. You can mount an Azure Files share using either protocol. The file share you define in the environment must be configured with the same protocol used by the file share in the storage account.
For new SMB file mounts, use managed identity authentication (preview) instead of storage account keys. Container Apps uses a system-assigned or user-assigned managed identity assigned to the Container Apps environment, not the individual container app, to authenticate to Azure Files. This mode eliminates the need to retrieve, store, or rotate a storage account key. You must explicitly select managed identity authentication in the storage definition; existing storage account key mounts remain supported.
Managed identity authentication applies only to SMB shares. NFS shares use network-based access controls and don't use SMB authentication settings.
To enable Azure Files storage in your container, set up your environment and container app as follows:
- Create a storage definition in the Container Apps environment.
- If you're using NFS, your environment must be configured with a custom VNet and the storage account must be configured to allow access from the VNet. For more information, see NFS file shares in Azure Files .
- If you're using NFS, the storage account must not require encrypted NFS connections. Container Apps doesn't support encryption in transit for NFS file shares. If the storage account's Require Encryption in Transit for NFS setting is enabled, or if that setting isn't configured and Secure transfer required is enabled, the mount fails with an error such as
mount.nfs: access denied by server while mounting. For more information, see Encryption in transit for NFS Azure file shares. - If your environment is configured with a custom VNet, you must allow ports 445 and 2049 in the network security group (NSG) associated with the subnet.
- Define a volume of type
AzureFile(SMB) orNfsAzureFile(NFS) in a revision. - Define a volume mount in one or more containers in the revision.
- The Azure Files storage account used must be accessible from your container app's virtual network. For more information, see Grant access from a virtual network.
Prerequisites
| Requirement | Instructions |
|---|---|
| Azure account | If you don't have one, create an account for free. |
| Azure Storage account | Create a storage account with a classic Azure file share. |
| Azure Container Apps environment | Create a container apps environment. |
| Managed identity for SMB authentication | Enable the environment's system-assigned managed identity or assign a user-assigned managed identity to the environment. See Manage environment identities. |
| Storage account settings for SMB managed identity authentication | Enable Managed Identity for SMB (SMBOAuth) on the storage account. Its SMB security settings must also allow Kerberos authentication. |
| Azure RBAC for SMB managed identity authentication | Assign the Storage File Data SMB MI Admin role to the selected environment identity at the storage account scope. See Assign a built-in RBAC role to the managed identity. To assign roles, you need Microsoft.Authorization/roleAssignments/write permission at that scope. Allow time for role assignments to propagate before mounting the share. |
Configuration
When you configure a container app to mount an Azure Files volume by using Azure CLI, you must use a YAML definition to create or update your container app.
Install the latest Azure CLI and update the Container Apps extension:
az extension add --name containerapp --upgrade
For a step-by-step tutorial on mounting an SMB file share, see Create an Azure Files storage mount in Azure Container Apps.
Add a storage definition to your Container Apps environment.
Managed identity authentication (recommended)
To use the environment's system-assigned managed identity, first enable it:
az containerapp env identity assign --name my-env --resource-group my-group \ --system-assignedGrant the identity the Storage File Data SMB MI Admin role on your storage account and enable Managed Identity for SMB as described in the prerequisites. Then create the storage definition:
az containerapp env storage set --name my-env --resource-group my-group \ --storage-name mystorage \ --storage-type AzureFile \ --azure-file-account-name <STORAGE_ACCOUNT_NAME> \ --azure-file-identity system \ --azure-file-share-name <STORAGE_SHARE_NAME> \ --access-mode ReadWriteReplace
<STORAGE_ACCOUNT_NAME>and<STORAGE_SHARE_NAME>with your storage account and file share names. The valuesystemselects the environment's system-assigned managed identity.To use a user-assigned managed identity instead, assign it to the environment:
az containerapp env identity assign --name my-env --resource-group my-group \ --user-assigned <MANAGED_IDENTITY_RESOURCE_ID>Grant that identity the same role on the storage account. In the storage command, replace
--azure-file-identity systemwith--azure-file-identity <MANAGED_IDENTITY_RESOURCE_ID>, using the identity's full Azure resource ID, not its client ID or principal ID.Don't combine
--azure-file-identitywith--azure-file-account-keyor--azure-file-key-vault-secret-url. These authentication modes are mutually exclusive.Storage account key authentication (alternative)
If you can't use managed identity authentication, you can use a storage account key instead:
az containerapp env storage set --name my-env --resource-group my-group \ --storage-name mystorage \ --storage-type AzureFile \ --azure-file-account-name <STORAGE_ACCOUNT_NAME> \ --azure-file-account-key <STORAGE_ACCOUNT_KEY> \ --azure-file-share-name <STORAGE_SHARE_NAME> \ --access-mode ReadWriteReplace
<STORAGE_ACCOUNT_NAME>and<STORAGE_ACCOUNT_KEY>with the name and key of your storage account. Replace<STORAGE_SHARE_NAME>with the name of the file share in the storage account.Valid values for
--access-modeareReadWriteandReadOnly.To update an existing container app to mount a file share, export your app's specification to a YAML file named app.yaml.
az containerapp show -n <APP_NAME> -g <RESOURCE_GROUP_NAME> -o yaml > app.yamlMake the following changes to your container app specification.
- Add a
volumesarray to thetemplatesection of your container app definition and define a volume. If you already have avolumesarray, add a new volume to the array.- The
nameis an identifier for the volume. - For
storageType, useAzureFilefor SMB, orNfsAzureFilefor NFS. This value must match the storage type you defined in the environment. - For
storageName, use the name of the storage you defined in the environment. - The
mountOptionsis a comma-separated string of mount options. For more information, see Use mountOptions settings in Azure Files. - The
secretslist is a list of secrets to mount in the volume. For more information, see Mounting secrets in a volume.
- The
- For each container in the template that you want to mount Azure Files storage, define a volume mount in the
volumeMountsarray of the container definition.- The
volumeNameis the name defined in thevolumesarray. - The
mountPathis the path in the container to mount the volume. - The
subPathis the path in the volume to mount. If you don't specify this value, the volume root is mounted. For more information, see Sub path.
- The
properties: managedEnvironmentId: /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME>/providers/Microsoft.App/managedEnvironments/<ENVIRONMENT_NAME> configuration: template: containers: - image: <IMAGE_NAME> name: my-container volumeMounts: - volumeName: azure-files-volume mountPath: /my-files subPath: my-sub-path volumes: - name: azure-files-volume storageType: AzureFile storageName: mystorage- Add a
Update your container app by using the YAML file.
az containerapp update --name <APP_NAME> --resource-group <RESOURCE_GROUP_NAME> \ --yaml app.yaml
For a full example, see the YAML specification.
The following ARM template snippets demonstrate how to add an Azure Files share to a Container Apps environment and use it in a container app. For SMB managed identity authentication, enable or assign the identity on the environment and complete the storage account prerequisites before deploying the storage definition.
Add a
storageschild resource to the Container Apps environment.Managed identity authentication (recommended)
First, enable a managed identity on the
Microsoft.App/managedEnvironmentsresource, not theMicrosoft.App/containerAppsresource. To enable the environment's system-assigned identity, add the following top-levelidentityproperty to your environment resource:{ "identity": { "type": "SystemAssigned" } }Merge this fragment into your existing environment resource, keeping its other configuration. Use an environment API version that supports managed identities, such as
2026-03-02-preview. For the resource schema, see Microsoft.App/managedEnvironments.Enable Managed Identity for SMB (
SMBOAuth) on the storage account and assign the environment identity the Storage File Data SMB MI Admin role at the storage account scope, as described in the prerequisites.Then use API version
2026-03-02-previewfor the storage resource. Setproperties.azureFile.identitytosystemto select the environment's system-assigned identity:{ "type": "Microsoft.App/managedEnvironments/storages", "apiVersion": "2026-03-02-preview", "name": "[concat(parameters('environment_name'), '/myazurefiles')]", "properties": { "azureFile": { "accountName": "[parameters('storage_account_name')]", "identity": "system", "shareName": "[parameters('storage_share_name')]", "accessMode": "ReadWrite" } } }To use a user-assigned managed identity instead, add it to the environment's top-level
identityproperty:{ "identity": { "type": "UserAssigned", "userAssignedIdentities": { "[parameters('managed_identity_resource_id')]": {} } } }Define the
managed_identity_resource_idparameter as astringcontaining the identity's full Azure resource ID. In the storage resource, setproperties.azureFile.identityto[parameters('managed_identity_resource_id')]instead ofsystem. Grant that identity the same role on the storage account.Preserve any identities already assigned to the environment. If you enable both identity types, use
SystemAssigned,UserAssignedfor the environment'sidentity.typeand retain itsuserAssignedIdentitiesentries.Don't include
accountKeyoraccountKeyVaultPropertieswhen using managed identity authentication. For the storage resource schema, see Microsoft.App/managedEnvironments/storages.Storage account key authentication (alternative)
To use a storage account key instead, set
accountKeyand omitidentity. Define thestorage_account_keytemplate parameter as asecureString.{ "type": "Microsoft.App/managedEnvironments/storages", "apiVersion": "2022-03-01", "name": "[concat(parameters('environment_name'), '/myazurefiles')]", "properties": { "azureFile": { "accountName": "[parameters('storage_account_name')]", "accountKey": "[parameters('storage_account_key')]", "shareName": "[parameters('storage_share_name')]", "accessMode": "ReadWrite" } } }These storage snippets assume that the environment and file share already exist. If you deploy them in the same template, add the environment and file share resources to the storage resource's
dependsOnarray. For managed identity authentication, also add a dependency on the role assignment if you create it in that template. A deployment dependency doesn't eliminate role assignment propagation delays.Update the container app resource to add a volume and volume mount.
SMB authentication is configured in the environment's storage definition. The app-level volume configuration is the same for managed identity and storage account key authentication. If you deploy the storage resource and container app in the same template, add the storage resource to the container app's
dependsOnarray.{ "apiVersion": "2023-05-01", "type": "Microsoft.App/containerApps", "name": "[parameters('containerappName')]", "location": "[parameters('location')]", "properties": { ... "template": { "revisionSuffix": "myrevision", "containers": [ { "name": "main", "image": "[parameters('container_image')]", "resources": { "cpu": 0.5, "memory": "1Gi" }, "volumeMounts": [ { "mountPath": "/myfiles", "volumeName": "azure-files-volume", "subPath": "my-sub-path" } ] } ], "scale": { "minReplicas": 1, "maxReplicas": 3 }, "volumes": [ { "name": "azure-files-volume", "storageType": "AzureFile", "storageName": "myazurefiles" } ] } } }- Add a
volumesarray to thetemplatesection of your container app definition and define a volume. If you already have avolumesarray, add a new volume to the array.- The
nameis an identifier for the volume. - For
storageType, useAzureFilefor SMB, orNfsAzureFilefor NFS. This value must match the storage type you defined in the environment. - For
storageName, use the name of the storage you defined in the environment. - The
mountOptionsis a comma-separated string of mount options. For more information, see Use mountOptions settings in Azure Files. - The
secretslist is a list of secrets to mount in the volume. For more information, see Mounting secrets in a volume.
- The
- For each container in the template that you want to mount Azure Files storage, define a volume mount in the
volumeMountsarray of the container definition.- The
volumeNameis the name defined in thevolumesarray. - The
mountPathis the path in the container to mount the volume. - The
subPath(optional) is the path in the volume to mount. If you don't specify it, the volume root is mounted. For more information, see Sub path.
- The
- Add a
See the ARM template API specification for a full example.
To configure a volume mount for Azure Files storage in the Azure portal, add a file share to your Container Apps environment and then add a volume mount to your container app by creating a new revision. For new SMB mounts, select managed identity authentication.
In the Azure portal, navigate to your Container Apps environment.
For SMB managed identity authentication, select Settings > Identity and enable a system-assigned identity or add a user-assigned identity to the environment. Complete the storage account settings and role assignment described in the Azure Files prerequisites before adding the share.
In the navigation pane, under Settings, select Volume mounts.
Select Add.
Select Server Message Block (SMB) or Network File System (NFS), depending on the protocol used by your file share.
In the Add file share context pane, enter the following information:
- Name: A name for the environment's storage definition.
- Storage account name: The name of the storage account that contains the file share.
- Authentication: Select Managed identity (recommended).
- Identity: Select the environment's system-assigned identity or a user-assigned identity assigned to the environment from the managed identity list. Select the identity that has the Storage File Data SMB MI Admin role on the storage account.
- File share name: The name of the SMB file share.
- Access mode: The access mode for the file share. Valid values are Read/Write and Read only.
To use storage account key authentication instead, select Storage account key under Authentication and enter the storage account's access key. Choose one authentication method for the storage definition.
Select Add to exit the context pane.
Select Save to commit the changes.
Go to your container app.
In the navigation pane, under Application, select Revisions and replicas.
Select Create new revision.
In the Create and deploy new revision page, select the Volumes tab.
Select Add.
In the Add volume context pane, set the following values.
- Volume type: Azure file volume.
- Name: Enter a volume name.
- File share name: Select the file share you created previously.
- Mount options: Optionally, enter a comma-separated string of mount options. For more information, see Use mountOptions settings in Azure Files.
Select Add to exit the context pane.
In the Create and deploy new revision page, select the Container tab.
Select the container that you want to mount the volume in.
In the Edit a container context pane, select the Volume mounts tab.
Under Volume name, select the volume you created previously.
In Mount path, enter the absolute path in the container to mount the volume.
In Sub path (optional), enter the path in the volume to mount. If you don't specify this value, the volume root is mounted. For more information, see Sub path.
Select Save to save changes and exit the context pane.
Select Create to create the new revision.
Sub path
When you mount a file share from Azure Files, you can specify both a mount path and a sub path.
- Mount path: The path in the container where you want to mount the volume.
- Sub path: The path in the volume you want to mount.
The sub path is optional. If you don't specify a sub path, the volume root is mounted.
The sub path is a relative path from the volume root. Don't start the sub path with /. If you specify a sub path that starts with /, your container app might not start. For example, my-volume-folder is a valid sub path, but /my-volume-folder isn't.
The sub path can refer to either a folder or a file in the volume.
If the sub path refers to a folder, the mount path should refer to an empty folder in the container.
If the sub path refers to a file, the mount path should refer to a file that doesn't already exist in the container.
For example, suppose the sub path is
my-volume-folder/my-volume-file.txt, and the mount path is/my-container-folder/my-container-file.txt. The folder/my-container-foldershould already exist in the container but shouldn't yet contain the filemy-container-file.txt.
The system ignores any sub path trailing slashes.