SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

com.mongodb.MongoTimeoutException #214

Closed myfreax closed 7 years ago

myfreax commented 7 years ago

reproduce

docker run -itd --name mongo -v /home/ubuntu/mongodb/:/data/db  -p 27017:27017 mongo
docker run --rm -i -t -d -p 8080:8080 --name restheart -v /home/ubuntu/restheart/restheart.yml:/opt/restheart/etc/restheart.yml  --link mongo softinstigate/restheart

Now open http:/.locahost:8080/ in browser

Result

{
    "_exceptions": [
        {
            "exception": "com.mongodb.MongoTimeoutException",
            "exception message": "Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=mongodb:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongodb}, caused by {java.net.UnknownHostException: mongodb}}]"
        }
    ],
    "http status code": 500,
    "http status description": "Internal Server Error",
    "message": "Timeout connecting to MongoDB, is it running?"
}
ujibang commented 7 years ago

you named your mongo container mongo and --link mongodb

shouldn't it be --link mongo?

myfreax commented 7 years ago

@ujibang I think I copied the wrong command line. if mongo container not found, the docker will show warning

docker: Error response from daemon: Could not get container for mongo.

Now,the command line has been fixed, you can according to command line reproduce

ujibang commented 7 years ago

Try with name and --link mongodb

I think the address specifie in conf file is mongodb

mkjsix commented 7 years ago

@huangyanxiong01 did you follow the documentation at https://hub.docker.com/r/softinstigate/restheart/ ?

myfreax commented 7 years ago

@mkjsix I konw you recommend to pull mongo:3.2 restheart 3.0.3. but I would like to use the new features of mongodb 3.4.4

mkjsix commented 7 years ago

@huangyanxiong01 with RESTHeart 3.x you can safely pull Mongodb 3.4, we use it extensively in our tests.

myfreax commented 7 years ago

@ujibang thank you, the mongodb container only name "mongodb", if container name "mongo" , the restheart will connect mongodb timeout.I don't think the address specifie in conf file is mongodb, it possible "mongodb" name in code

mkjsix commented 7 years ago

@huangyanxiong01 if you are pulling the official softinstigate/restheart docker image then the default configuration is taken from https://github.com/SoftInstigate/restheart/tree/master/Docker/etc so mongo-uri: mongodb://mongodb

myfreax commented 7 years ago

@ujibang Yes,thank you,I already understand