skip to Main Content

I want to integrate and test Azure File Storage from my Web application, and before deploying it to the environment (where an Azure Shared folder is provisioned), I would like to test it on my local.

I have a docker container running Azurite on my local, and I am able to emulate an Azure Blob Storage Container on my local machine, connect with it and test.

I just want to be able to do the same for Azure File Storage. I don’t see support for the same in Azurite or the deprecated Azure Storage Emulator. As per the 5th point of official Microsoft docs – (https://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator#differences-between-the-storage-emulator-and-azure-storage), "The File service and SMB protocol service endpoints aren’t currently supported in the Storage Emulator.".

Is there a way to emulate File Storage on Azurite? Or any other supporting application, docker image, etc.?

2

Answers


  1. One option is to mount the file share directly to a running docker container as a CIFS share. I tested this on the latest Ubuntu docker image pulled from docker hub. To authenticate to the file share, you’ll need the storage account’s name and access key which can be found in the portal view for your particular storage account.

    Pull the latest image and run it specifying --privileged flag to avoid mount: <mount-path>: permission denied errors

    docker pull ubuntu:latest
    docker run -it --entrypoint /bin/sh --privileged ubuntu:latest
    

    Install cifs-utils package in case its missing

    apt update
    apt install cifs-utils -y
    

    In my example, the file share is named root so I mount it at /mnt/root in the container.

    STORAGE_ACCOUNT_NAME="<your_storage_account>"
    ACCESS_KEY="<access_key>"
    
    mkdir /mnt/root
    if [ ! -d "/etc/smbcredentials" ]; then
    mkdir /etc/smbcredentials
    fi
    if [ ! -f "/etc/smbcredentials/$STORAGE_ACCOUNT_NAME.cred" ]; then
        bash -c 'echo "username='$STORAGE_ACCOUNT_NAME'" >> /etc/smbcredentials/'$STORAGE_ACCOUNT_NAME'.cred'
        bash -c 'echo "password='$ACCESS_KEY'" >> /etc/smbcredentials/'$STORAGE_ACCOUNT_NAME'.cred'
    fi
    chmod 600 /etc/smbcredentials/$STORAGE_ACCOUNT_NAME.cred
    
    bash -c 'echo "//'$STORAGE_ACCOUNT_NAME'.file.core.windows.net/root /mnt/root cifs nofail,vers=3.0,credentials=/etc/smbcredentials/'$STORAGE_ACCOUNT_NAME'.cred,dir_mode=0777,file_mode=0777,serverino" >> /etc/fstab'
    mount -t cifs //$STORAGE_ACCOUNT_NAME.file.core.windows.net/root /mnt/root -o vers=3.0,credentials=/etc/smbcredentials/$STORAGE_ACCOUNT_NAME.cred,dir_mode=0777,file_mode=0777,serverino,nosharesock,actimeo=30
    

    Similar instructions to mount the share can also be found through the portal: Your-Storage-Account > File shares > Your-share > Connect.

    Login or Signup to reply.
  2. There is currently no emulator for File shares, but one of the workarounds is that you may use PowerShell by creating a storage account in Azure and leverage the file share as a local drive on your local machine.

    For more information on this, you can follow Use an Azure file share with Windows

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search