Docker Community Forums

Share and learn in the Docker community.

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

(Majjaz) #1

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 --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 --eval 'db.getSiblingDB(“dashboard”).createUser({user: “db”, pwd: “dbpass”, roles: [{role: “readWrite”, db: “dashboard”}]})'
MongoDB shell version: 3.0.7
connecting to:
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 --eval 'db.getSiblingDB(“dashboard”).createUser({user: “db”, pwd: “dbpass”, roles: [{role: “readWrite”, db: “dashboard”}]})'
MongoDB shell version: 3.0.7
connecting to:
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
image: mongo:latest
container_name: mongodb
command: mongod --smallfiles

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