dokku / dokku-mongo

a mongo plugin for dokku
MIT License
177 stars 32 forks source link

Using "replSet" in MONGO_CONFIG_OPTIONS #88

Closed ohardy closed 6 years ago

ohardy commented 7 years ago

If i export MONGO_CONFIG_OPTIONS with :

export MONGO_CONFIG_OPTIONS=" --auth --replSet example "

And i create a new mongo database with :

dokku mongo:create test

It's just return just after the first echo in functions.sh L54.

dokku mongo:connect test

give me :

connecting to: mongodb://127.0.0.1:27017/test
MongoDB server version: 3.4.6
2017-08-02T12:21:27.542+0000 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1461:20
@(auth):6:1
@(auth):1:2
exception: login failed

If i try manually to run the docker command got with trace, i get :

2017-08-02T12:15:42.339+0000 E QUERY    [thread1] Error: couldn't add user: not master :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1292:15
@(shell):1:1
bye
josegonzalez commented 7 years ago

I've never used replSet, so I don't really know what either of those errors mean.

malixsys commented 6 years ago

@ohardy I'm trying to convert my container, too...

Direct running needs a patch https://github.com/docker-library/mongo/issues/211#issuecomment-344347819

Meanwhile, did you try to invert the options?

--replSet example --auth

wootwoot1234 commented 6 years ago

@ohardy Did you ever get this working?

@malixsys I tried inverting the options as suggested but no luck. Still can't connect. Any other ideas?

malixsys commented 6 years ago

I got it to work “à postériori”.. I’ll try and create a gist...

malixsys commented 6 years ago

YMMV

(updated for latest version)

nano  /var/lib/dokku/services/mongo/YOUR_SERVICE/MONGO_CONFIG_OPTIONS
 --replSet rs0  --storageEngine wiredTiger --auth
sudo docker pull mongo:3.6
dokku mongo:upgrade YOUR_SERVICE  -I 3.6
dokku mongo:upgrade YOUR_SERVICE  -I 3.6.13
dokku mongo:connect-admin YOUR_SERVICE

// IN MONGO

use admin
rs.initiate()
use local
db.system.replset.find()
exit
StefanoDeVuono commented 6 years ago

@malixsys is correct. As per mongo's documentation a standaone db needs to be initiated to run as a replica set.

rs.initiate()

Then wait until the prompt says PRIMARY or SECONDARY.

josegonzalez commented 6 years ago

Closing as this isn't really in the scope of this plugin, and I think folks have a sufficiently good answer to get started down this path.

archy-bold commented 4 years ago

For anyone struggling with @malixsys's code not working, it's likely because your MongoDB version is already up to date and the dokku mongo:upgrade command doesn't run and restart the container. To do that instead of upgrading, do the following:

docker rm dokku.mongo.YOUR_SERVICE
dokku mongo:start YOUR_SERVICE

Hat tip https://realmenweardress.es/2019/07/running-rocketchat-on-a-dokku-paas-server/

archy-bold commented 4 years ago

Quick question for those in the discussion: Did any of you manage to use a hostname other than the container ID? I've tried updating it but realise I need to update the /etc/hosts file in order to do it. I though maybe that would be possible with the docker-options plugin but it only seems to work on dokku apps and not plugin containers.

kamzata commented 1 year ago

This is what I receive:

admin> rs.initiate()
MongoServerError: This node was not started with replication enabled.