Authentication in Mongo DB is not working in Azure Container Instance when deploying with Azure File Share as mount volume

Md Farman Khan 36 Reputation points
2020-11-24T12:42:34.563+00:00

I am deploying mongo db container as Azure container instance in a group using Azure CLI YAML script. Here I am using a Azure file share as a mount volume, while using this mount volume the authentication is not enabled in mongo db. Though without mount volume it is working fine. Here is my YAML script:

apiVersion: '2019-12-01'
location: southindia
name: xyz
properties:
  containers:
  - name: xyz-mongo
    properties:
      environmentVariables: 
      - name: MONGO_INITDB_ROOT_USERNAME
        value: xyz
      - name: MONGO_INITDB_ROOT_PASSWORD
        secureValue: xyz
      image: xyz.azurecr.io/xyz/mongo:4.2.8
      command: ['mongod', '--dbpath', '/data/mongoaz']
      ports:
      - port: 27017
      resources:
        requests:
          cpu: 1.0
          memoryInGB: 1.0
      volumeMounts:
      - name: xyzstore
        mountPath: /data/mongoaz
  osType: Linux
  restartPolicy: Always
  ipAddress:
    type: Public
    ports:
      - protocol: tcp
        port: 27017
    dnsNameLabel: xyz
  volumes:
  - name: xyzstore
    azureFile:
      sharename: xyz
      storageAccountName: xyz
      storageAccountKey: xyz
  imageRegistryCredentials:
  - server: xyz.azurecr.io
    username: xyz
    password: xyz
tags: {}
type: Microsoft.ContainerInstance/containerGroups
Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
643 questions
0 comments No comments
{count} vote

4 answers

Sort by: Most helpful
  1. prmanhas-MSFT 17,891 Reputation points Microsoft Employee
    2020-11-25T13:25:26.8+00:00

    @Md Farman Khan Apologies for the delay in response and all the inconvenience caused because of the issue.

    Mounting an Azure Files share to a container instance is similar to a Docker bind mount. Be aware that if you mount a share into a container directory in which files or directories exist, these files or directories are obscured by the mount and are not accessible while the container runs.

    So it's not recommended to mount the Azure File Share to the existing directory which contains the files used to initialize the Mongo DB. The recommend directory will like path /var/logs/ which might be the reason you are not able to do so.

    More information here.

    Hope it helps.

    Do let me know if you have any further queries.

    Please 'Accept as answer' if it helped, so that it can help others in the community looking for help on similar topics


  2. Bruno Cardoso 1 Reputation point
    2021-04-19T20:14:57.29+00:00

    Hello @Md Farman Khan , Im having the same problem, you solved it? I am deploying a container with mongodb and API as Azure container instance but the authentication its not works. If you have some news about it, please share with me.


  3. Gerben Limburg 1 Reputation point
    2021-05-07T16:44:13.373+00:00

    I had the same problem.
    It turns out you have to run a script like the following:

    mongo
    use admin
    db.createUser(
      {
        user: "mongo-admin",
        pwd: "-",
        roles: [{role: "root", db: "admin"}]
      }
    )
    

    I haven't figured out how to integrate this into an arm template yet.


  4. Raman Kesava Palla 1 Reputation point
    2021-11-30T04:55:45.82+00:00

    Hello:
    I am interested in this question. May i know if there is a solution found out yet?

    Cheers,
    Raman