Mount an emptyDir volume in Azure Container Instances
Learn how to mount an emptyDir volume to share data between the containers in a container group in Azure Container Instances. Use emptyDir volumes as ephemeral caches for your containerized workloads.
Note
Mounting an emptyDir volume is currently restricted to Linux containers. While we are working to bring all features to Windows containers, you can find current platform differences in the overview.
emptyDir volume
The emptyDir volume provides a writable directory accessible to each container in a container group. Containers in the group can read and write the same files in the volume, and it can be mounted using the same or different paths in each container.
Some example uses for an emptyDir volume:
- Scratch space
- Checkpointing during long-running tasks
- Store data retrieved by a sidecar container and served by an application container
Data in an emptyDir volume is persisted through container crashes. Containers that are restarted, however, aren't guaranteed to persist the data in an emptyDir volume. If you stop a container group, the emptyDir volume isn't persisted.
The maximum size of a Linux emptyDir volume is 50 GB.
Mount an emptyDir volume
To mount an emptyDir volume in a container instance, you can deploy using an Azure Resource Manager template, a YAML file, or other programmatic methods to deploy a container group.
First, populate the volumes
array in the container group properties
section of the file. Next, for each container in the container group in which you'd like to mount the emptyDir volume, populate the volumeMounts
array in the properties
section of the container definition.
For example, the following Resource Manager template creates a container group consisting of two containers, each of which mounts the emptyDir volume:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"container1name": "aci-tutorial-app",
"container1image": "mcr.microsoft.com/azuredocs/aci-helloworld:latest",
"container2name": "aci-tutorial-sidecar",
"container2image": "mcr.microsoft.com/azuredocs/aci-tutorial-sidecar"
},
"resources": [
{
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2021-03-01",
"name": "volume-demo-emptydir",
"location": "[resourceGroup().location]",
"properties": {
"containers": [
{
"name": "[variables('container1name')]",
"properties": {
"image": "[variables('container1image')]",
"resources": {
"requests": {
"cpu": 1,
"memoryInGb": 1.5
}
},
"ports": [
{
"port": 80
}
],
"volumeMounts": [
{
"name": "emptydir1",
"mountPath": "/mnt/empty"
}
]
}
},
{
"name": "[variables('container2name')]",
"properties": {
"image": "[variables('container2image')]",
"resources": {
"requests": {
"cpu": 1,
"memoryInGb": 1.5
}
},
"volumeMounts": [
{
"name": "emptydir1",
"mountPath": "/mnt/empty"
}
]
}
}
],
"osType": "Linux",
"ipAddress": {
"type": "Public",
"ports": [
{
"protocol": "tcp",
"port": "80"
}
]
},
"volumes": [
{
"name": "emptydir1",
"emptyDir": {}
}
]
}
}
]
}
To see examples of container group deployment, see Deploy a multi-container group using a Resource Manager template and Deploy a multi-container group using a YAML file.
Next steps
Learn how to mount other volume types in Azure Container Instances: