MongoDB docker container got reset

Nicolas O 20 Reputation points
2023-06-08T10:02:46.9333333+00:00

I have in my resource group a docker container with a mongoDB inside, yesterday there was data in it, today it was empty.
It's not the first time that happened.

I guessed, it has something to do with a restart of the container, after I manually restarted my container, the data was all gone too.

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
757 questions
{count} votes

Accepted answer
  1. deherman-MSFT 38,021 Reputation points Microsoft Employee Moderator
    2023-06-08T15:03:07.3633333+00:00

    @Nicolas O

    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!

    User's image

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.