question

Derek-4231 avatar image
2 Votes"
Derek-4231 asked DenisPapathanasiou-1198 commented

Azure App Services w/ Docker Compose volume persistence question

I am trying to understand how persistence is managed with App Services when using Docker Compose.

Here's my simple config:

version: "3.7"
services:
  n8n:
    image: xxx.azurecr.io/n8nio/n8n:0.113.0
    restart: always
    volumes:
      - n8n-data:/n8n/data

volumes:
  n8n-data:
    driver: azure_file
    driver_opts:
      share_name: shareName
      storage_account_name: storageName


I've observed the following:

  1. It boots up, and I can write to disk (sqlite).

  2. Data survives a reboot and stop/start of my app.

  3. If I go looking for my the contents of my share name, I do not see any data being written to it (where is the data being written?)


I've also tried the same config w/o any volumes defined, and I noticed that data does not survive reboots, which is what I would expect. I guess the strange thing I'm trying to figure out is...where is this data? Perhaps I don't need to explicitly say anything about azure_file and just mention volumes generally and it works? This is pretty underdocumented behavior so I wanted to understand what I can rely on and what I can't.

I'm using Basic B1 tier app service plan.

azure-webapps
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ryanchill avatar image
2 Votes"
ryanchill answered DenisPapathanasiou-1198 commented

Hi @Derek-4231,

I'm thinking you're using https://github.com/Azure/azurefile-dockervolumedriver. You want to look for a storage account that contains a file share that matches storage_account_name and share_name respectively. Using your simple config, you can run:

az storage share-rm show --name shareName --storage-account storageName --resource-group the-app-resource-group

From the CLI. Also be aware that this driver is longer supported. However, you can still link your container your app to storage (in preview). In this example,

 version: "3.7"
 services:
   n8n:
     image: xxx.azurecr.io/n8nio/n8n:0.113.0
     restart: always
     volumes:
       - n8n-data:/n8n/data

The name of the storage mount would be n8n-data and the mount path the folder insider your container i.e. /n8n/data.

84380-image.png

Regards,
Ryan


image.png (123.1 KiB)
· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This works! It wasn't immediately intuitive from reading any docs, but I tried this and it works exactly as I expected it to. Thank you

2 Votes 2 ·

Hi, just a clarification in @ryanchill 's answer above: the mount path which you specify when creating the Azure Storage Mount is not taken into account. The only mount path that is important to define is the path specified in the "volumes" entry of the Docker Compose file.

1 Vote 1 ·

Hi @ryanchill,

Thank you for posting this, I was having the same exact experience as @Derek-4231 using the legacy driver: azure_file in my docker compose file.

I did try what you suggested, and while I do now have an Azure Mount Point defined in my App Service as /data, now when I try starting my container, I get his error:

 2021-10-31T17:37:36.430Z ERROR - multi-container unit was not started successfully
 2021-10-31T17:37:36.434Z INFO  - Container logs from banrai_app_0_5c6be327 = 2021-10-31T17:37:21.757620974Z python3: can't open file '/data/app.py': [Errno 2] No such file or directory
 2021-10-31T17:37:26.639026165Z python3: can't open file '/data/app.py': [Errno 2] No such file or directory

And sure enough, when I look inside my storage account, I do not see any reference to /data.

Do I need to create something called /data there first?

0 Votes 0 ·
ryanchill avatar image ryanchill DenisPapathanasiou-1198 ·

Is your code running from the /data folder @DenisPapathanasiou-1198?

0 Votes 0 ·

Yes, @ryanchill, my Dockerfile looks like this:

WORKDIR /data

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

CMD ["python3", "app.py"]


That worked just fine with the legacy azure_drive settings in the docker compose yaml (and just like @Derek-4231 I noticed the volume survived restarts of the app service), but it seems incompatible with defining the azure storage mount explicitly, even when I do that first, before attempting to start the app service

0 Votes 0 ·
ryanchill avatar image ryanchill DenisPapathanasiou-1198 ·

If you want /data to be persisted to your storage account, I would separate your code and data directories e.g.

WORKDIR /src


This avoids having your code files to be persisted along with your data. Then create a /data folder under /src and update your mount path in the Azure portal to /src/data. Let me know if that helps.

1 Vote 1 ·

That resolved it, thank you

1 Vote 1 ·