Connect to mongodb move from docker container
So I want to connect to my mongodb running on my host machine (DO droplet, Ubuntu 16.04). It works 27017
by default on local 27017
.
I then use mup to deploy a Meteor app on a DO blob, which uses Docker to run a Meteor app inside a container. So far, so good. The standard mongodb://...
connection url is used to connect the app to mongodb. Now I have the following problem:
mongodb://...@localhost:27017...
obviously does not work inside a docker container since it is localhost
not localhost.
I've already read a lot of posts about this and I've already tried using:
-
--network="host"
- didn't work, as it was said0.0.0.0:80
already used or something like that (nginx proxy) -
--add-host="local:<MY-DROPLET-INTERNET-IP>"
and connect viamongodb://...@local:27017...
: also doesn't work, since I can only access my mongodb from localhost, not from public IP
This should be a common problem!
tl; dr - How do I properly expose localhost
host hosts inside a docker container so that I can connect to services running on the host? (including their ports, for example 27017).
I hope someone can help!
source to share
You can use: 172.17.0.1
as this is the default host ip that containers can see. But you need to configure Mongo to listen 0.0.0.0
.
From docker on 18.03 onwards, it is recommended to connect to a dedicated DNS namehost.docker.internal
For previous versions, you can use DNS names docker.for.mac.localhost
or docker.for.windows.localhost
.
source to share