have been trying to connect my docker node.js app to a mongodb service to no avail. I've created a was liberty bridging application ($BRIDGE_APP) with no war or code that is bound to a mongodb service. It is running with good status. Have to say that the same code is running correctly in my local docker container. I am using mongoose to connect to mongo.The only difference in the code is the way of resolving the 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 to connect to 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 my image to bluemix with no issues:
ice --local push $REGISTRY/$ORG/$CONTAINER_NAME
I then check the env vars:
cf env $BRIDGE_APP
System-Provided:
{
"VCAP_SERVICES": {
"mongodb-2.4": [
{
"credentials": {.....
and then I run my container and bind an 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 is almost completely by the book, but for some reason when I check the logs I'm always getting:
ice logs $CONTAINER_NAME
...
going to connect to mongo@: mongodb://c61deb58-45ea-41....
Example app listening at http://0.0.0.0:8080
connection error: { [MongoError: connect ENETUNREACH] name: 'MongoError', message: 'connect ENETUNREACH' }
I have also tried with mongolab service with no success.
Has anybody somehow eventually tried this type of setup that can provide me some additional clue of what's missing here?
thanking you in advance