0

I'm trying to deploy Mongo onto Azure Container Instances as part of a container group. To do this, I use a Storage Account with a file share to persist the mongo data. It's impossible to mount the volume in the /data/db default location, so I mount it elsewhere and start mongod using the --db-path flag. This all works fine using the CLI, full command below.

However, when I want to translate all of these commands into my YAML config file it doesn't work. Mongo crashes out with an unknown file or directory error. If I start the container without the --db-path flag but still mount the volume, I can exec into the running container and see that the volume is there and is attached. I can even manually create folders in the share via the Azure Portal and see them appear in the container.

Documentation and examples are a little thin on the ground, especially YAML based examples. The biggest difference with the container group is having to define a named volume separate from the container which is used by the volumeMounts property. Is it just a syntax error? Are the CLI command and the YAML not equivalent in some way?

CLI Command

az container create
--resource-group rsenu-hassPilots-group
--name mongo
--image mongo
--azure-file-volume-account-name <account>
--azure-file-volume-account-key "<key>" --azure-file-volume-share-name mongodata
--azure-file-volume-mount-path "/data/mongoaz"
--ports 27017
--cpu 1
--ip-address public
--memory 1.5
--os-type Linux
--protocol TCP
--command-line "mongod --dbpath=/data/mongoaz"

YAML Config

apiVersion: 2018-10-01
location: uksouth
name: trustNewArtGroup
properties:
  containers:
  - name: mongo
    properties:
      image: mongo:4.2.3
      resources:
        requests:
          cpu: 1
          memoryInGb: 1.5
      ports:
      - port: 27017
      volumeMounts:
      - name: database
        mountPath: /data/azstorage
      environmentVariables:
      - name: 'MONGO_INITDB_DATABASE'
        value: 'trust-new-art-db'
      command:
      - "mongod --dbpath=/data/azstorage"
  osType: Linux
  ipAddress:
    type: Public
    dnsNameLabel: trustnewart
    ports:
    - protocol: tcp
      port: '27017'
  volumes:
    - name: database
      azureFile:
        sharename: mongodata
        storageAccountName: <account>
        storageAccountKey: <key>
tags: null
type: Microsoft.ContainerInstance/containerGroups
Mark
  • 816
  • 1
  • 9
  • 27
  • Have you tried single quotes for your yaml command? I've had this give different outcomes (not specifically for this scenario) especially if deploying from a linux agent/host – Bevan Feb 08 '20 at 23:59
  • Also, I think ` mountPath ` Property will need quotes as well. – Bevan Feb 09 '20 at 00:05
  • Thanks for the suggestions @Bevan, I've made those changes but it still won't start. Interestingly I changed the command argument to `'ls /data/azstorage'` and that also throws a directory not found error. – Mark Feb 09 '20 at 10:22

1 Answers1

3

With a bit of help from this page in the documentation, I've discovered it was a syntax issue. The correct way to override the entrypoint in a YAML config file is as follows:

command: ['mongod', '--dbpath', '/data/azstorage']
Mark
  • 816
  • 1
  • 9
  • 27
  • I opened a case with Microsoft and resolved it before they came back. I then stumbled across this page with my same exact issue. I submitted a PR to fix their yaml documentation reference page – Jimmy R Apr 22 '20 at 21:13