1
votes

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 ?

1
Any more questions? Does it solve your problem? Please give the response. - Charles Xu

1 Answers

1
votes

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.