-
Notifications
You must be signed in to change notification settings - Fork 632
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
Initialize admin username/password and DB doesn't seems to be working ... #174
Comments
Was your database already created? The env vars will not create a user on an already created database, but they do ensure mongod is started with If there is nothing important in there you can always If you need the data, you can see if there are actually any users created; jump into the container with a
|
Thanks for the tip, deleting database works for me. |
@yosifkit ...
I don't think so since I did a
Yes, there nothing is important - for now - so I can try the given command
This is not necessary, in this scenario data is useless to me.
I am not sure to be understanding what the issue is here but if I am getting you correct then I need to have some scripts under |
Once you insert something in the database it will show up, otherwise you can just use any "database" that you want. |
I've been stuck on this for a while, but I think I figured it out. The mongo instance defaults to test database however the database where the username and password you create is on the admin database. You're able to switch databases using 'use admin' and then authenticating will work. |
This comment has been minimized.
This comment has been minimized.
How did you do this to be precise? |
@letavia, you just need to set the From the env vars section of the docs on docker hub, $ docker run -it --rm --link some-mongo:mongo mongo mongo --host mongo -u mongoadmin -p secret --authenticationDatabase admin some-db To make it a little simpler, lets skip the link and assume you have a hostname of $ docker run -it --rm mongo:4.0 mongo --host my-mongo -u mongoadmin -p secret --authenticationDatabase admin mydbname
# or
$ docker run -it --rm mongo:4.0 -u mongoadmin -p secret --authenticationDatabase admin mongo my-mongo/mydbname |
Totally agree with you. This is pure evil! Wasted 5 freaking hours of my life! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@vutran1710 I was able to solve it with the default mongo docker image by adding this to
And then adding the following to
|
Like everyone else here, I did the same as the OP and it did not work. But the solution posted by @johnwyles does work. So is the documentation wrong? Which is the officially supported way - the OP's code, or the |
@yosifkit re-reading through all of your comments I do not think you seem to fully understand the issue that myself and all the others on this issue have discussed and @lonix1 and myself have found the fix I mentioned above. The point here is not to get on the docker image and play around with the user that is created, not to login or get a shell on the docker image, not to run ANY pre or post mongo commands whatsoever on the container but for the docker container to simply start mongo already initialized with an administrative username and password. That is it. There is nothing more to the issue and the point here is that it appears that NONE of the environment variables |
What was implemented in #145 was the ability to create a "root" user with superuser access to the entire MongoDB instance using only environment variables: Lines 291 to 301 in 5ab118c
It is created with an explicit "role" of Given that authentication is very flexible in MongoDB, we did not want to overcomplicate the initialization script with more than that bare minimum behavior. If something more complex or customized is required, that's exactly what The only thing I would suggest changing there is to remove the use of the |
@tianon This is probably now more of a Mongo question but if I were to only supply: MONGO_INITDB_DATABASE: mydatabase
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_ROOT_USERNAME: admin And then leave out: - ./data/mongo/001_users.js:/docker-entrypoint-initdb.d/001_users.js:ro Would I be able to authenticate against the DB? What if I wanted a Last question: what is MONGO_INITDB_DATABASE: mydatabase
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_ROOT_USERNAME: admin That it would create a database named |
@tianon I agree with @johnwyles - the reason so many of us (and lots more on StackOverflow) misunderstoof #145 is that it describes obviously necessary behavior, which we need - but the actual behavior isn't useful. There should be a way to easily create a preconfigured container, with a new database with a username and password, via Doing this via an extra
At the very least the docs should cover this use case and show comment 174 as an official solution. (Until hopefully the behavior we need is added.) |
@johnwyles BTW it only works for me if I keep the So basically, unless I am misunderstanding this problem (and if I am it's not my fault because the docs are not clear), this entire feature is problematic. |
I have filed a new issue to address todays ongoing discussion so please comment and share thoughts there: #329 |
For those who are still having issues for not being able to change their root password/username after supplying the environment variables (Works for me):
*updating your root password is live and no restarts are required |
I am using some features from this PR #145 (which is not documented BTW :) ) but it seems not to be working since I am getting the following error from my application:
This is how my
docker-compose.yml
file looks like:And the
.env
file has this content:From my understanding and the PR code I would expect:
mongousradmin
user is createdmongousradmin
password is set tomongopassadmin
container
DB is initializedAny ideas about what could be wrong here? If I remember correct right after the PR was approved I test this and was working so either I am missing something or isn't working anymore
The text was updated successfully, but these errors were encountered: