node.js - bluemix docker container bind to mongodb ('MongoError', message: 'connect ENETUNREACH') -
have been trying connect docker node.js app mongodb service no avail. i've created liberty bridging application ($bridge_app) no war or code bound mongodb service. running status. have same code running correctly in local docker container. using mongoose connect mongo.the difference in code way of resolving mongo connection string:
var db_connect_string = 'mongodb://app:password@127.0.0.1:27017/appname'; if(custom.areweonbluemix() && custom.dowehaveservices()) db_connect_string = custom.getmongoconnectstring(); ... console.log('going connect mongo@: ' + db_connect_string); var db = mongoose.createconnection(db_connect_string); db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function (callback) { console.log('... db open !!!'); });
i push image bluemix no issues:
ice --local push $registry/$org/$container_name
i check env vars:
cf env $bridge_app system-provided: { "vcap_services": { "mongodb-2.4": [ { "credentials": {.....
and run container , bind ip:
ice run --bind $bridge_app --name $container_name -p $port $registry/$org/$container_name:latest sleep 12 ice ip bind $ip $container_name
...this book, reason when check logs i'm getting:
ice logs $container_name ... going connect mongo@: mongodb://c61deb58-45ea-41.... example app listening @ http://0.0.0.0:8080 connection error: { [mongoerror: connect enetunreach] name: 'mongoerror', message: 'connect enetunreach' }
i have tried mongolab service no success.
has somehow tried type of setup can provide me additional clue of what's missing here?
thanking in advance
it has been experience networking not reliable in ibm containers 5 seconds @ startup. try adding "sleep 10" cmd or entrypoint. or set retry x seconds before giving up.
once networking comes has been reliable me. first few seconds of containers life have had troubles dns, binding, , outgoing traffic.
i gave similar answer a similar question recently. perhaps problem same other poster's.
Comments
Post a Comment