Bring Your Own Storage

Bring your own storage is a new feature available on Docker based runtimes on Azure App Service. This includes both Windows based Containers as well as Web App on Linux and Web App for Containers. What is really cool about this feature is that, it makes it super easy to connect a storage hosted in Azure (Blobs/FileShares) easily to your web app.

Here is the az-cli command to add an Azure storage Account to your web app.

az webapp config storage-account add -g "JlawDemoRG" -n "JlawDemoWebApp" 
 --custom-id AzureShare
 --storage-type AzureFiles
 --accountName "JlawDemoStorageAccount"
 --share-name "TestShare"
 --mount-path /home/data 
 --access-key ***

While the command looks really long, it is fairly easy to understand. The key parameters which require additional explanation:

--custom-id: A moniker or identifier for the storage account. This is really useful for referencing the storage account when used in a multi-container configuration file.

--mount-path: Path in the container where the storage account is mounted to.

Can I serve static content from Azure Files easily with app service?

Of course, the answer is Yes!!! We’ve already blogged about using nginx in App-Service, we can extend the same nginx docker image based container to serve static files hosted in Azure Storage.

Below is an example with setting up Nginx with Web App for Containers (WAfC)

az webapp create -g "JlawDemoRG" -p "JlawDemoASP" -n "JlawDemoNginxApp" 
  --deployment-container-image-name "nginx:latest"
az webapp config storage-account add -g "JlawDemoRG" -n "JlawDemoNginxApp" 
 --custom-id AzureShare 
 --storage-type AzureFiles 
 --accountName "JlawDemoStorageAccount" 
 --share-name "TestShare" 
 --mount-path /usr/share/nginx/html 
 --access-key ***

The official nginx image expects content share to be in /usr/share/nginx/html. By specifying the --mount-path to the same location, nginx is now able to fetch the content from the storage account and serve it out.

For a multi-container web app, below is a sample compose file:

version: '3.1'

services:

  nginx:
    image: nginx:latest
    ports:
      - 8080:80
    volumes:
      - AzureShare:/usr/share/nginx/html


Note that we used the --custom-id value “AzureShare” to reference the share in the compose file.

Credits

A huge thanks to Eben Carek, our summer intern who coded up this feature! I’m so happy to share your work out to the world :)