cnizzardini
cnizzardini

Reputation: 1240

MongoDB data not persisting between taking docker containers down and up again [MacOSX]

When I take docker containers down and up again, my MongoDB collections are all gone.

It works fine if I am just stopping and starting the containers though. My host machine is macOS Mojave 10.14 with Docker Desktop 2.1.

I have the following docker-compose.yaml version 3.4 file:

  mongodb:
      image: mongo:4.2.1
      volumes:
           - ./docker/data/mongodb:/var/lib/mongodb:rw
      ports:
      - target: 27017
        published: 27018
        protocol: tcp

I am not sure what I am doing wrong with the volume mounts. When I look on my host machine at ./docker/data/mongodb nothing is being written to it, ever. I went ahead and set permissions to 777 on that to see if it was a permissions issue, hail mary, I know.

Upvotes: 1

Views: 974

Answers (2)

Valijon
Valijon

Reputation: 13113

You are missing quotes

volumes:
       - "./docker/data/mongodb:/var/lib/mongodb"

Note: MongoDB by default points /data/db

Upvotes: 1

w08r
w08r

Reputation: 1814

From the docs here:

https://hub.docker.com/_/mongo

You will need to mount the custom volume into /data/db, not /var/lib/mongodb

Upvotes: 0

Related Questions