Search code examples
yamldocker-volumeazure-container-apps

Unable to mount a volume in Azure Container App


I have been trying to build and deploy a Docker image of the nopCommerce website to the new-ish Azure Container Apps service. I have had some success in building the container in Azure DevOps to an Azure container registry, starting the container and having it connect to an Azure SQL DB I'm having issues with getting the the container to mount a shared volume based on Azure Storage SMB File Share (in order to store a shared appsettings.json file and other config across containers). I have been trying to follow the MS documentation here but have become unstuck on trying to carry out the update to the app.yaml file to add a storage mount to my existing container. Step 1: (See link above) registers my storage in the Container App environment and returns without issue on the Azure CLI.

Step 2: As per the instructions I run the command below on the Azure CLI to pull down my container app described in .yaml structure.

az containerapp show -n <APP_NAME> -g <RESOURCE_GROUP_NAME> -o yaml > app.yaml

Step 3: Suggests editing the file to include a mount description based on the storage I added in step 1 (see link). I had several goes at this using Visual Studio Code to keep my yaml formatting on point (not used it before) but every time I tried to upload the edited yaml as per the command below (Step 4) I get an error on the CLI.

az containerapp update --name <APP_NAME> --resource-group <RESOURCE_GROUP_NAME> \
--yaml my-app.yaml

The command failed with an unexpected error. Here is the traceback:

unacceptable character #x0000: special characters are not allowed
in "app.yaml", position 3
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 663, in execute
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 726, in _run_jobs_serially
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 718, in _run_job
File "C:\Users\craig.azure\cliextensions\containerapp\azext_containerapp_client_factory.py", line 28, in _polish_bad_errors
raise ex
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 697, in _run_job
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 333, in call
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
File "C:\Users\craig.azure\cliextensions\containerapp\azext_containerapp\custom.py", line 700, in update_containerapp
return update_containerapp_logic(cmd,
File "C:\Users\craig.azure\cliextensions\containerapp\azext_containerapp\custom.py", line 512, in update_containerapp_logic
return update_containerapp_yaml(cmd=cmd, name=name, resource_group_name=resource_group_name, file_name=yaml, no_wait=no_wait, from_revision=from_revision)
File "C:\Users\craig.azure\cliextensions\containerapp\azext_containerapp\custom.py", line 124, in update_containerapp_yaml
yaml_containerapp = process_loaded_yaml(load_yaml_file(file_name))
File "C:\Users\craig.azure\cliextensions\containerapp\azext_containerapp\custom.py", line 100, in load_yaml_file
return yaml.safe_load(stream)
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\yaml/init.py", line 125, in safe_load
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\yaml/init.py", line 79, in load
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\yaml/loader.py", line 34, in init
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\yaml/reader.py", line 85, in init
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\yaml/reader.py", line 135, in determine_encoding
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\yaml/reader.py", line 169, in update
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\yaml/reader.py", line 143, in check_printable
yaml.reader.ReaderError: unacceptable character #x0000: special characters are not allowed
in "app.yaml", position 3

As a sanity test I ended up NOT making any edits to the app.yaml file and just trying to update (as per Step 3) with the original file that was created in (as per Step 2) and I am still getting this error! I am doing this on a Windows 10 laptop and getting to the point of paranoia where I am wondering if yaml is sensitive enough to object to different CR LF line endings... Has anyone successfully manage to mount an Azure FileShare in Azure Container Apps using these instructions and if so can they see where I am going wrong? Also could they share a redacted version of the successful yaml file as the one that gets created for me does not match the format shown the documentation for the process, my .yaml file has a - command[] part to it (see below) which is not shown in the example yaml snippet.

   template:
    containers:
    - command: []
      env:
      - name: AZURE_SQL_CONNECTIONSTRING
        secretRef: azure-sql-connectionstring-52068
      image: myregistry.azurecr.io/nopcommerce:2
      name: mynopcommerce-store-container-app
      resources:
        cpu: 0.25
        memory: 0.5Gi
    scale:
      maxReplicas: 10

Solution

  • I just had this issue a few days ago. The issue ended up being that the file is in UTF-16 LE BOM encoding and the BOM adds an invisible character at the beginning of the file that Azure does not like. If you switch it to an encoding without the BOM (I used UTF-8) it should work like a charm.