How to mount storage in Azure Containers

0

Guide to Setting Up a File Share for Your Azure Container App

In this tutorial, we will guide you through the process of setting up an Azure file share and binding it to a container environment. This setup is essential for providing persistent storage that your container app can access.

Here is a link to the docker files if you wanted to see the Dockerfile or .py script.

Step 1: Create a File Share in Azure Storage

  1. Open the Storage Account
    • Navigate to your Azure storage account.
    • Go to Storage Browser > File Shares.
  2. Add a File Share
    • Click Add File Share.
    • Name your file share anything you’d like. We will reference this name later in the container environment.
    • For this guide, we will use the name 'containerappfilestorage'.
This image shows where to create a file share in azure storage
Where to create a file share in azure storage
This image shows the file share I created for this tutorial. The name is important later!
The file share I created for this tutorial. The name is important later!

Step 2: Bind the File Share to the Container Environment

  1. Open the Container App Environment
    • In the Azure portal, navigate to your Container App Environment.
    • Go to Azure Files > Add > SMB File Share.
  2. Fill in the Required Information:
    • Name: You can give it any name you want.
    • Storage Account Name: Enter the name of your storage account.
    • Storage Account Key: This can be found in your storage account under Access Keys. Make sure to copy the Key and not the connection string.
    • File Share Name: Enter the name of the file share you created earlier (in our case, containerappfilestorage).
    • Access Mode: For this tutorial, set the access mode to Read/Write. Note that for some applications, Read-only access is recommended to ensure stability, especially if the app crashes or is interrupted during file writing, which can lead to file corruption.
  3. Add the File Share
    • Once all the information is entered, click Add to bind the file share to the environment.
    • Don’t forget to save the file share to the environment!
This shows were to add Azure Files Storage in the Container App Environment.
This shows were to add Azure Files Storage in the Container App Environment.
This image shows the Add SMB file share prompt.
This shows the Add SMB file share prompt.
This image shows where the access keys are located in your storage account.
This shows where the access keys are located in your storage account.

Step 3: Attach the File Share to Your Container App

  1. Open Your Container App
    • Navigate to the container app you want to bind the file share to.
  2. Create a Volume
    • Go to Volumes > Add.
    • Select the file share you just added to the environment.
    • Click Add and then Save as a new revision.
This image shows how to mount the SMB share as a volume in you container app.
This shows how to mount the SMB share as a volume in you container app.

Step 4: Bind the File Share to Your Container

  1. Create a New Revision for the Container
    • Navigate to Revisions and Replicas.
    • Click Create a new revision.
  2. Add a New App Container
    • Configure the Docker image for your container.
    • Name: Choose a label for your container (this can be whatever you prefer).
    • Image Source: Select Docker Hub.
    • Image Type: Set this to Public.
    • Login Server: Set this to docker.io.
    • Image and Tag: For this tutorial, we’ll be using the image icefire555/azuredatatest:latest, but you can use your own Docker image.
  3. Configure Volume Mounts
    • Go to the Volume Mounts tab.
    • Select the storage name from the volume you just added.
    • Set a mount path. For this guide, we’ll use /data.
  4. Save and Deploy
    • Save the container and click Create to start the deployment.
This image shows you how do create a new revision so we can configure our docker image to be pulled.
This shows you how do create a new revision so we can configure our docker image to be pulled.
This image shows how to create a new app container.
This shows how to create a new app container.
This image shows the settings used to pull a docker image from Docket Hub.
This shows the settings used to pull a docker image from Docket Hub.
This image shows how to mount the volume to your container.
This shows how to mount the volume to your container.

Step 5: Monitor Your Container’s Logs

  1. View the Console Logs
    • After deployment, select your revision and open the Console Logs to monitor the container’s performance.
  2. Storage Access
    • If the container has already run, you can view the output file in the Storage Browser of your Azure storage account.
This image shows how to check your container logs.
This shows how to check your container logs.
This image shows what the output will look like on the first run.
This shows what the output will look like on the first run.
This image shows what the output will look like on future runs.
This shows what the output will look like on future runs.
This image shows the file the code created in the file share.
This shows the file the code created in the file share.

By following these steps, you should now have a fully configured Azure file share bound to your container app, ready for deployment and use. Feel free to modify these instructions to suit your specific application needs!

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *