-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
How to use .ddev/docker-compose.mongo-extra.yaml to expose mongo port to host #15
Comments
Hi @bfuzze , thanks for your message. Regarding the To access a mongodb UI, did you try the provided mongo-express ? (run By the way, if your modification is ok for you, you should create a For example, create a
Thanks |
Are you saying that you want a process on the host to access your mongo-in-container ? Mongo uses a non-http protocol, so can't be proxied like HTTP can, so the ddev-router can't be used. So yes, if you're doing this, you'll need to expose the port, and the way you're doing it is correct, but as @julienloizelet says, use a separate override file to do it, and then you won't be preventing your ddev-mongo add-on from ever being upgraded again. @julienloizelet I agree that |
That is correct. I have a Node script running outside the container which requires access to the MongoDB instance, so I exposed the port (similar to other db container conventions).
|
I guess I don't think it's "normal" to add this kind of access, so maybe the docs don't need any update. Note that doing this means that you can't run two projects at the same time that use this, although each could have a different port specified. |
A small hook (requires hooks:
post-start:
- exec-host: echo "Connect to MongoDB with mongodb://db:db@$(docker inspect $(ddev status -j | jq -r .raw.services.mongo.full_name) | jq -r '.[0].NetworkSettings.Networks."ddev-'$(ddev status -j | jq -r '.raw.name')'_default".IPAddress'):27017" Without hooks:
post-start:
- exec-host: echo "Connect to MongoDB with mongodb://db:db@$(docker inspect $(ddev status -j | docker run -i --rm ddev/ddev-utilities jq -r .raw.services.mongo.full_name) | docker run -i --rm ddev/ddev-utilities jq -r '.[0].NetworkSettings.Networks."ddev-'$(ddev status -j | docker run -i --rm ddev/ddev-utilities jq -r '.raw.name')'_default".IPAddress'):27017" Can be useful if you don't use This is something similar to our database scripts (e.g. |
In places where jq may not be available, use |
There might be a better way, but I added this to docker-compose.mongo.yaml in order to make the instance accessible outside of DDev environments.
In addition, I had to adjust connection credentials to use separate auth-database 'admin' and auth-protocol to SCRAM-SHA1.
The README states the default database is 'api', but I didn't see a database with this name, so I used 'local'.
Otherwise, very easy to setup.
Thanks.
The text was updated successfully, but these errors were encountered: