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.

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 Quotas and region availability for Azure Container Instances.

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, are not guaranteed to persist the data in an emptyDir volume.

Mount an emptyDir volume

To mount an emptyDir volume in a container instance, you must deploy using an Azure Resource Manager template.

First, populate the volumes array in the container group properties section of the template. 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/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "container1name": "aci-tutorial-app",
    "container1image": "microsoft/aci-helloworld:latest",
    "container2name": "aci-tutorial-sidecar",
    "container2image": "microsoft/aci-tutorial-sidecar"
  },
  "resources": [
    {
      "name": "volume-demo-emptydir",
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2018-02-01-preview",
      "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 an example of container instance deployment with an Azure Resource Manager template, see Deploy multi-container groups in Azure Container Instances.

Next steps

Learn how to mount other volume types in Azure Container Instances: