3

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 Answers1

1

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.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • 1
    I added the startup command in my docker-compose, it mounted `data/mongod` to my storage. But now i get another error ` F STORAGE [initandlisten] Reason: 1: Operation not permitted` what happens is when the mongodb container tries to check the `WiredTiger.w` file it fails, so it restarts the container and it finds the same file there and creates another one `WiredTiger.w.2` and so on. How to solve this? – Mohamad Sobhie Feb 26 '20 at 15:31
  • @MohamadSobhie Do not put the command inside the docker-compose file. I also tried it. But it didn't work. Just follow the CLI command in the answer. It works fine. – Charles Xu Feb 27 '20 at 01:02
  • your command doesn't work for me, the app works fine but i don't see any files in my storage, will specifying the mongodb path at the creation of the app make it as the startup command for every time i recreate the mongodb container ? – Mohamad Sobhie Feb 27 '20 at 11:13
  • @MohamadSobhie Yes, every time you create the Web App needs the startup command. As it shows the reason in the link you provided. – Charles Xu Feb 28 '20 at 05:49