It is possible that the data loss is caused by the restart of the container. By default, Azure Container Instances are stateless. If the container is restarted, crashes, or stops, all of its state is lost. To persist state beyond the lifetime of the container, you must mount a volume from an external store.
In your case, it seems that the MongoDB data is not stored in a persistent volume. To persist the data, you can mount an emptyDir volume to the container group, or use an Azure file share . The emptyDir volume provides a writable directory accessible to each container in a container group. Containers in the group can read and write the same files in the volume, and it can be mounted using the same or different paths in each container.
To mount an emptyDir volume in a container instance, you can deploy using an Azure Resource Manager template, a YAML file, or other programmatic methods to deploy a container group. First, populate the volumes array in the container group properties section of the file. Next, for each container in the container group in which you'd like to mount the emptyDir volume, populate the volumeMounts array in the properties section of the container definition.
Hope this helps!
If you still have questions, please let us know in the "comments" and we would be happy to help you. Comment is the fastest way of notifying the experts.
If the answer has been helpful, we appreciate hearing from you and would love to help others who may have the same question. Accepting answers helps increase visibility of this question for other members of the Microsoft Q&A community.
Thank you for helping to improve Microsoft Q&A!