How to run MongoDB and Mongo-express with docker-compose?

前端 未结 8 2101
情话喂你
情话喂你 2021-02-14 07:10

I try to run MongoDB and Mongo-express by Docker-compose. I use following config:

version: \'3\'

services:
    mongo:
        image: mongo
        environment:
         


        
8条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 08:17

    In case you are still having this issue... Or in case someone else is going absolutely crazy trying to figure out why none of this works...

    Running docker-compose up --force-recreate

    Doesn't recreate the container completely (not sure why) - it DOES look like it did, but I figured out that it wasn't recreating the container's data (databases!) when I got into the DB without Auth, and a collection that I created an hour ago was still there.

    I had run the above command, and also 'docker image rm mongo' as well as removing the mongo-express (Not needed)

    The problem is I had to do a 'docker container list' to see the two containers I had (one for Mongo by itself and one for Mongo with Mongo-express - not sure which I needed to delete, but I deleted them both...)

    Once I did that, and did the 'up' your configuration pulling the values from the .env file worked fine - it did the INITDB... and set the Admin passwords correctly in the database!

    So, if you EVER created it with any configuration to test it, you will have a container that it is reusing the data for (I think it doesn't recreate that to avoid data loss - I mean, 99.9% of the time you just want to recreate the PROGRAM part, not the data - otherwise you would lose your databases.)

    Killed a couple hours figuring this one out...

提交回复
热议问题