Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up authentication fails. #49

Closed
jjelev opened this issue Aug 1, 2015 · 5 comments
Closed

Set up authentication fails. #49

jjelev opened this issue Aug 1, 2015 · 5 comments

Comments

@jjelev
Copy link

jjelev commented Aug 1, 2015

It would be nice to have env variables for authentication enabling, to set username/password, storage engine .. etc.
For guideline I have been using https://github.com/tutumcloud/mongodb/tree/master/2.6
Here is my dockerfile:

FROM mongo:2.6

RUN mongo admin --eval "db.createUser({user: 'myuser', pwd: 'mypass', roles:[{role:'dbOwner',db:'admin'}]});"

The build returns:

MongoDB shell version: 2.6.10
connecting to: admin
2015-08-01T00:59:42.877+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-08-01T00:59:42.878+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

Expected result - to build the image and set up new user.

@codingwithoutcomments
Copy link

I agree would great to have a variable i could set to enable auth.

@DmitryEfimenko
Copy link

DmitryEfimenko commented Jun 17, 2016

Failed to connect to 127.0.0.1:27017

You are getting this error because it takes a bit of time to start up mongo service. It seems people are using something like the following to avoid it:
Dockerfile:

FROM mongo:3.2.0
COPY setup.sh /setup.sh
RUN /setup.sh

setup.sh:

#!/bin/bash

mongod --dbpath /data/db &

RET=1
while [[ RET -ne 0 ]]; do
    echo "=> Waiting for confirmation of MongoDB service startup"
    sleep 5
    mongo admin --eval "help" >/dev/null 2>&1
    RET=$?
done

ADMINUSER=user
ADMINPASS=pass

echo "=> Creating an admin user in MongoDB"
mongo admin --eval "db.createUser({user: '$ADMINUSER', pwd: '$ADMINPASS', roles:[{role:'root',db:'admin'}]});"

mongod --dbpath /data/db --shutdown

However, after successfully building this image, and starting a container using this image with command --auth I can't seem to be able to connect to the database using user I created above. Anybody has idea why?

@tianon , your input would be very appreciated!

@xgdgsc
Copy link

xgdgsc commented Apr 29, 2017

I also think it would be great to have a variable I could set to enable auth.

@yosifkit
Copy link
Member

yosifkit commented May 1, 2017

@xgdgsc, like #145? (Still fixing bugs added by this, which is why it is not documented).

@yosifkit
Copy link
Member

Closing old issue, fixed by #145. Feel free to comment if you feel this was closed in error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants