Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-37482

Mongo runninng from autorestarting docker fails authentication

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 4.0.2
    • Component/s: Admin
    • None
    • ALL
    • Hide

      Start an unsecured mongo container.

      docker run --volume ~/test-data:/data/db --publish --name mongo-unauthenticated 27017:27017 mongo:4.0.2

      Connect to it and create some users:
      {{mongo
      use admin
      db.createUser(

      { user: "admin", pwd: "password", roles: [ \{ role: "userAdminAnyDatabase", db: "admin" }

      , "readWriteAnyDatabase" ]
      }
      )
      use test
      db.createUser(

      { user: "tester", pwd: "password", roles: [ \{ role: "readWrite", db: "test" }

      ]
      } )
      exit}}

      Now take the unsecured mongo offline:

      docker stop mongo-unauthenticated

      And put a secured version in place. Note the `--restart always` flag that causes the container to autostart.

      docker run --restart always --publish 27017:27017 --name test-mongo -v ~/test-data:/data/db mongo:4.0.2 --auth

      Check that you can connect with valid credentials:

      mongo --port 27017 -u "tester" -p "password" --authenticationDatabase "test"

      Make a clean shutdown:

      docker stop mongo-unauthenticated

      Restart your computer.

      reboot

      Check that the `--restart always` works.

      docker ps

      And get the authentication failed with pristine credentials.

      mongo --port 27017 -u "tester" -p "password" --authenticationDatabase "test"

      Show
      Start an unsecured mongo container. docker run --volume ~/test-data:/data/db --publish --name mongo-unauthenticated 27017:27017 mongo:4.0.2 Connect to it and create some users: {{mongo use admin db.createUser( { user: "admin", pwd: "password", roles: [ \{ role: "userAdminAnyDatabase", db: "admin" } , "readWriteAnyDatabase" ] } ) use test db.createUser( { user: "tester", pwd: "password", roles: [ \{ role: "readWrite", db: "test" } ] } ) exit}} Now take the unsecured mongo offline: docker stop mongo-unauthenticated And put a secured version in place. Note the `--restart always` flag that causes the container to autostart. docker run --restart always --publish 27017:27017 --name test-mongo -v ~/test-data:/data/db mongo:4.0.2 --auth Check that you can connect with valid credentials: mongo --port 27017 -u "tester" -p "password" --authenticationDatabase "test" Make a clean shutdown: docker stop mongo-unauthenticated Restart your computer. reboot Check that the `--restart always` works. docker ps And get the authentication failed with pristine credentials. mongo --port 27017 -u "tester" -p "password" --authenticationDatabase "test"

      Dear developers, 

      I am not quite sure if this is on topic here, but it might interest you.

      I am running a mongodb docker container on my machine and I want to have it start when I start my computer. However, each time I boot my computer I have to do a docker restart of the container because the "automatically started" container slaps me with an Authentication failed  when I give it valid credentials. Manually restarting the offending container solves the problem immediately.

      I am running an Ubuntu 18.04 system, on an encrypted partition, with the latest docker and MongoDB 4.0.2 (althought I had this problem with every version I tried). Oddly enough, this problem does not occur on an unencrypted partition.

      I would like to know if this could possibly be caused by the encryption of the partition (During Ubuntu installation you have the choice to encrypt). 

            Assignee:
            nick.brewer Nick Brewer
            Reporter:
            drozdik.svk@gmail.com Martin Drozdik
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: