Why is my machine getting contaminated by a process in the Container(mongoldb)?

I was working on testing and open source project that uses mongo and I noticed that when I re-create the container it is contaminated by prior actions, only deleting the machine gets me back to the pristine state that I need.

This is fully reproducible on my mac using toolbox 1.9.0

  1. create a machine
    docker-machine create -d virtualbox dashboard
    eval “$(docker-machine env dashboard)”

  2. run the docker-compose file (see below)
    docker-compose up -d

  3. Setup a user id on the db
    mongo 192.168.99.109/admin --eval ‘db.getSiblingDB(“dashboard”).createUser({user: “db”, pwd: “dbpass”, roles: [{role: “readWrite”, db: “dashboard”}]})’

** This is the important part, notice the create id worked**

➜ Hygieia git:(collectors) ✗ mongo 192.168.99.102/admin --eval 'db.getSiblingDB(“dashboard”).createUser({user: “db”, pwd: “dbpass”, roles: [{role: “readWrite”, db: “dashboard”}]})'
MongoDB shell version: 3.0.7
connecting to: 192.168.99.109/admin
Successfully added user: {

  • “user” : “db”,*

  • “roles” : [*

  •   {*
    
  •   	"role" : "readWrite",*
    
  •   	"db" : "dashboard"*
    
  •   }*
    
  • ]*
    }

    docker-compose restart

  1. delete the container and then recreate it
    docker-compose stop
    docker-compose rm
    docker-compose up -d

5. now try to create the id, we get an error it already exists! We expected this to succeen.

➜ mongotest git:(master) mongo 192.168.99.102/admin --eval 'db.getSiblingDB(“dashboard”).createUser({user: “db”, pwd: “dbpass”, roles: [{role: “readWrite”, db: “dashboard”}]})'
MongoDB shell version: 3.0.7
connecting to: 192.168.99.102/admin
2015-12-15T14:00:17.753-0800 E QUERY Error: couldn’t add user: User “db@dashboard” already exists
at Error ()
at DB.createUser (src/mongo/shell/db.js:1101:11)
at (shell eval):1:30 at src/mongo/shell/db.js:1101

6. if we delete the machine and start all over again this is fully reproducible.

➜ mongotest git:(master) cat docker-compose.yml
mongodb:
image: mongo:latest
container_name: mongodb
command: mongod --smallfiles
ports:

  • "27017:27017"
    volumes:
  • ./mongo:/data/db:rw
    volume_driver: local