Skip to content

Instantly share code, notes, and snippets.

@Bastianowicz
Last active October 17, 2021 17:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bastianowicz/7960afaac1c921f0f83c42aedca43ddf to your computer and use it in GitHub Desktop.
Save Bastianowicz/7960afaac1c921f0f83c42aedca43ddf to your computer and use it in GitHub Desktop.
Solved: MongoDB in Docker (AWS ECS) loses all the data after redeployment

MongoDB in Docker loses all collections after Redeploy on AWS ECS

Setup:

  • MongoDB image running in ECS on EC2 t2.small
    • Task has a volume added that is "shared" and should thus survive the recreation its container
    • tasks container has the volume mounted on /data

Reproduction:

  • Insert a document
  • (force) redeploy the task

Expectation

  • MongoDB has the document after the containers recreation

Experience

  • MongoDB has no Documents and is launched "clean"

Solution

  • Mount your volume at /data/db
    • also mount a second volume at /data/configdb to keep your configuration (e.g. replication) persistent

Explanation

  • The base docker image alreade defines two volumes at /data/configdb and /data/db
  • These volumes have no persistence defined and are being deleted on container shutdown
  • if you mount your volume at /data that leaves the default defined volumes untouched no matter what you define in your volume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment