Docker running host but not accessible

when u start a container, it gets its OWN ip address, and localhost INSIDE the container is not the same as the host.

by default, mongodb and mysql cone configured to listen ONLY for localhost…(or 127.0.0.1).
this means the container is listening for connections from INSIDE the container, not outside.

so, you must change the config to listen for the host or other container, or ANY ip address calling it.

So I need to change my mongodb path into

Mongodb-uri= mongodb://localhost:27017/dbname

or

Mongodb-uri= mongodb://192.168.1.174:27017/dbname

if I give any ip address to connect the mongodb I am unable to get it because in my login page inspect I am getting 192.168.99.100:8088/login failed message. so If I try to connect 192.168.99.100:27017 db path it will throw error. I am getting little confusion in this db path and running application ip

Where Should Change? to resolve that problem. and one more question is there any way to run the docker application by using localhost :8088 ? will it run or not.

I need to connect my system or anyother system db to that running application. how to achieve it. can u explain it clearly. I already posted my environment file(mongodb path) and docker running ip. My db or others system db I want to connect by using ip address of the system it is not connecting to the mongodb…

Please help me to login to system.

there are two parts to this

1 the mongodb server
2. the application trying to USE the database

for step 1, in the mongodb startup use mondgd --bind_ip_all
to allow ANY application, on ANY other IP address to connect to the database.
by default, mongodb will ONLY allow applications from the SAME system (host->host, container->container) to connect
see https://docs.mongodb.com/manual/reference/program/mongod/

then 2, the application must use the IP address of the mongodb container, which is NOT the same as the host machine… on linux the container would typically be at 172.17.0.x in that range anyhow…

  1. This is my mongod.config file

destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
net:
// Listen to local and LAN interfaces.
bindIp: 127.0.0.1,192.168.1.88,192.168.1.174
port: 27017

  1. the application must use the IP address of the mongodb container, which is NOT the same as the host machine… on linux the container would typically be at 172.17.0.x

where should I give this ip address

when you connect from the application to the db server (container), you would use container_ip_address:27017

which container ip address : application container ip_address or mongodb container ip address?

How to find container ip addresss

@sdetweil
I have used already exists mongo containers which is available in docker. By using pull command i used docker pull mongo

by using docker ps i am getting container id of mongo

Then I used docker inspect container-id (mongo container-id)

it is displaying ip address as 172.1.0.2 now what should give to connect my db.

and also I gave bindIp: 127.0.0.1,172.1.0.2 in mongod.config file

127.0.0.1 is mongodb default ip address.

172.1.0.2 is mongo container ip address

both ip address is not connecting the mongodb
showing mongodb connection error only.

mongodb_uri=“monogdb://172.1.0.2:27017/pmsdb”

mongodb_uri=“monogdb://127.0.0.1:27017/pmsdb”

both is showing error.

I dont know What mistake i am doing here. Please help me to sort out the problem of local db connection with docker application

172.17.0.2 is the ip address of the mongo server…

in the server config set bindIp: 0.0.0.0
0.0.0.0 means any

then restart the mongo server

then from your db client app the connection would be to 172.17.0.2:27017

then I have to run my application ?
docker run -p 8088:8088 nitikishu/samplenodejs

it will run in 192.168.99.100:8088 or 172.17.0.2:8088?

you do not need to map the ports to access the docker container

so, http://172.17.0.2:8088 should work (application/web browser running on the docker host)

this is my mongodb_uri=“mongodb://172.17.0.2:27017/pmsdb” path right?

yes,

AND

the mongodb server config bindip: 0.0.0.0
to allow ANY ip address (docker host or another container) to connect to the database server

this is not reaching the site. I followed ur steps. But still I am unable to get it in this ip address

env file:

MONGODB_URI=mongodb://172.17.0.2:27017/sample_DB
SESSION_SECRET=sample
App_PORT = 8088

mongod.config

systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
net:
bindIp: 0.0.0.0

command:
docker run nitikishu/samplenodejs

on running application every time container ip address will change?

Before u said This ip 192.168.99.100:8082 check the application running host.

Now ur saying 172.17.0.2:8088 host. I have confused. ///Now this ip is not running

I am confused as well… what is your docker host? windows, linux? i cannot remember.

please describe again the two sides of your solution

server side

app side

Hi @sdetweil,

docker-machine env default
Docker_host=“tcp://192.168.99.100:2376”

I am using winodws 8.

I developed one sample application using (mean stack technology). I want to run this application in all environment(in every where also). So I start to use docker to run my sample application. for that I have built , push the image into docker using (docker quickstart terminal). Now when I run that application in docker by docker run nitikishu/samplenodejs command I am getting following message:

> $ docker run -p 8088:8088 nitikishu/samplenodejs
> sampleproject@1.0.0 start /C:Usersuser2Sample
> node server.js
> server running on port 8088
> Press CTRL-C to stop
> MongoDB connection error. Please make sure MongoDB is running.

in my application I gave mongodb path like this:

MONGODB_URI=mongodb://192.168.99.100:27017/sample_DB
App_PORT = 8088

I want to access my system database(I am using the database named as pmsdb) I want to access that db with the sample application in docker.

I dont know how to connect mongodb database into that docker. Which path should I give also I don’t know. Because When I run the application in my system I will use mongodb path ="monogdb://localhost:27017/sample_DB
If I use the same path in docker built application It is not working.

using docker -machine ip address 192.168.99.100:8088 I am running my project. But Db which ip address I should give?

yesterday you said to bind all ip in mongod.config file. I done that by below code

mongodb.cfg file (this file is in mongodb installed path of my local windows system c:mongodb/bin/mongod.cfg)

systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
net:
bindIp: 0.0.0.0

Now How to connect my local db into samplenodejs application which is running in docker.

Mongodb version :3.4.2
ip address of mongodb: 127.0.0.1:27017

Here, I included the steps which I followed to run the application in docker

##         .
  ## ## ##        ==
   ## ## ## ## ##    ===
   /"""""""""""""""""\___/ ===
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
   \______ o           __/
 \    \         __/
  \____\_______/

docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

Start interactive shell

user2@system2 MINGW64 ~
$ cd sample

user2@system2 MINGW64 ~/sample
$ docker --version
Docker version 17.05.0-ce, build 89658be

user2@system2 MINGW64 ~/sample
$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v17.06.0-ce

user2@system2 MINGW64 ~/sample
$ docker build -t nitikishu/samplenodejs .
Sending build context to Docker daemon   48.7MB
Step 1/7 : FROM node:carbon
 ---> b87c2ad8344d
Step 2/7 : WORKDIR C:\Users\user2\Sample
 ---> Using cache
 ---> 3880524e00d9
Step 3/7 : COPY package*.json ./
 ---> Using cache
 ---> 6e116b22c908
Step 4/7 : RUN npm install
 ---> Using cache
 ---> a31a7a85f633
Step 5/7 : COPY . .
 ---> 7124ff43c59c
Removing intermediate container c8e8c639d7f0
Step 6/7 : EXPOSE 8088
 ---> Running in 4cd031953ed5
 ---> 9c252b8cb2c2
Removing intermediate container 4cd031953ed5
Step 7/7 : CMD npm start
 ---> Running in 19910c6a969f
 ---> 36e4e33d1466
Removing intermediate container 19910c6a969f
Successfully built 36e4e33d1466
Successfully tagged nitikishu/samplenodejs:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' p
ermissions. It is recommended to double check and reset permissions for sensitive files and directories.

user2@system2 MINGW64 ~/sample
$ docker push nitikishu/samplenodejs
The push refers to a repository [docker.io/nitikishu/samplenodejs]
4638b36f4098: Pushed
bc17d0d0ec47: Layer already exists
d228ef051c7d: Layer already exists
0697092f077d: Layer already exists
092504c250f7: Layer already exists
299e6ab856be: Layer already exists
50599c766115: Layer already exists
d4141af68ac4: Layer already exists
8fe6d5dcea45: Layer already exists
06b8d020c11b: Layer already exists
b9914afd042f: Layer already exists
4bcdffd70da2: Layer already exists
Head https://registry-1.docker.io/v2/nitikishu/samplenodejs/blobs/sha256:36e4e33d1466f119410498bd88b9a33d51c4792cbd7a2810dbf455e8ca8f4ce4: net/http: TLS handshake timeout

user2@system2 MINGW64 ~/sample
$ docker pull nitikishu/samplenodejs
Using default tag: latest
latest: Pulling from nitikishu/samplenodejs
Digest: sha256:7db75ca39cf597ac92a5fa3f459d5315f8909c6042e14a491238026bfdd24892
Status: Downloaded newer image for nitikishu/samplenodejs:latest

user2@system2 MINGW64 ~/sample
$ docker run -p 8088:8088 nitikishu/samplenodejs

> sampleproject@1.0.0 start /C:Usersuser2Sample
> node server.js

 server running on port 8088
  Press CTRL-C to stop

 MongoDB connection error. Please make sure MongoDB is running.

user2@system2 MINGW64 ~/sample
$

thanks… it is still unclear what you mean by the word ‘local’ for the mongo db…

do you mean running on the machine on which you started docker.

there is windows machine
there is virtual machine inside windows (the docker host)
and there is the container…

i THINK you are saying you want the application, running in the container on the virtual machine to connect to the mongo DB running natively on windows. (because your steps do not include starting a mongo db server container)

I will wait for your reply…

yes… In my machine I have a mongodb database. I want to access my system and also LAN connected(local machine) database. In my system only I am running docker.

yes @sdetweil… my application running in the docker container. I want to connect to mongodb database which is running in my own system .