Mohamad Sobhie
Mohamad Sobhie

Reputation: 141

Mounting Mongodb volume to Azure files in Azure Web App for Containers

I have an app that runs as a docker container, the app connects to another container which is Mongodb, I want to mount the mongodb volume data/db to Azure share files. I am using docker compose file to define my containers. Assuming that I already have a storage account linked to the app, this is how I define my docker volume in docker-compose

  database:
    image: "mongo:latest"
    container_name: database
    ports:
      - "27017:27017"
    volumes: 
      - ${WEBAPP_STORAGE_HOME}/data/db:/data/db

In Unable to mount azure file shares as mongodb volume in azure container instances it was mentioned that mounting data/db is not recommended and it won't work. My question is:

How can I mount my mongodb files to Azure files ? how to perform back-ups to those files? and if i want to restore a backup to the database would it be possible to just upload the files in the azure files and see them in my mongodb ?

Upvotes: 3

Views: 2697

Answers (2)

Jijo John
Jijo John

Reputation: 1674

I spent almost three days figuring this out. The same issue occurs whether it's a wwwroot or Azure file share mounted to a Linux web app.

MongoDB's underlying storage driver - WiredTiger relies on fsync for normal operations. which is NOT supported by these file systems

2024-05-24T13:25:08.217694048Z {"t":{"$date":"2024-05-24T13:25:08.217+00:00"},"s":"W",  "c":"STORAGE",  "id":22347,   "ctx":"initandlisten","msg":"Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade."}
2024-05-24T13:25:08.217731949Z {"t":{"$date":"2024-05-24T13:25:08.217+00:00"},"s":"F",  "c":"STORAGE",  "id":28595,   "ctx":"initandlisten","msg":"Terminating.","attr":{"reason":"1: Operation not permitted"}}
2024-05-24T13:25:08.217747150Z {"t":{"$date":"2024-05-24T13:25:08.217+00:00"},"s":"F",  "c":"ASSERT",   "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":28595,"file":"src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp","line":676}}
2024-05-24T13:25:08.217758950Z {"t":{"$date":"2024-05-24T13:25:08.217+00:00"},"s":"F",  "c":"ASSERT",   "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}
{"ts_sec":1716557488,"ts_usec":355840,"thread":"1:0x7c1089a3ec80","session_name":"connection","category":"WT_VERB_BLOCK","category_id":3,"verbose_level":"NOTICE","verbose_level_id":-1,"msg":"unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.102"}}}
2024-05-24T13:31:28.364110000Z {"t":{"$date":"2024-05-24T13:31:28.362+00:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":1,"message":{"ts_sec":1716557488,"ts_usec":362215,"thread":"1:0x7c1089a3ec80","session_name":"connection","category":"WT_VERB_DEFAULT","category_id":9,"verbose_level":"ERROR","verbose_level_id":-3,"msg":"__posix_open_file:815:/data/db/WiredTiger.wt: handle-open: open","error_str":"Operation not permitted","error_code":1}}}

https://github.com/docker-library/mongo/issues/528

On cosmosdb - there are limitations and not all features are supported https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/feature-support-60 let not supported

Upvotes: 0

Charles Xu
Charles Xu

Reputation: 31452

For your issue, just as I said in another issue you find. To mount the Azure File Share to Web App will override the existing files in the image. So you need to change the MongoDB data path when the Azure File Share is already mounted.

The example docker-compose file like this:

version: '3.7'

services:
   web:
     image: mongo:latest
     ports:
       - "27017:27017"
     volumes:
       - fileshare:/data/mongodb

And create the Web App with this docker-compose file and set the start file with value mongod --dbpath=/data/mongodb --bind_ip_all. For example, if you use the Azure CLI, the create command like this:

az webapp create -g group_name --plan plan_name -n web_name --multicontainer-config-type compose --multicontainer-config-file docker-compose-file --startup-file "mongod --dbpath=/data/mongodb --bind_ip_all"

Finally, you need to set the file share mount like below:

enter image description here

Or follow the steps through CLI in Configure your app with Azure Storage.

Upvotes: 1

Related Questions