Docker two tier application issue: failed to connect to mongo container -


i have simple nodejs application consisting of frontend , mongo database. want deploy via docker.

in docker-compose file have following:

version: '2' services:   express-container:     build: .     ports:      - "3000:3000"     depends_on:      - mongo-container   mongo-container:     image: mongo:3.0 

when run docker-compose up, have following error:

creating todoangularv2_mongo-container_1 ... creating todoangularv2_mongo-container_1 ... done creating todoangularv2_express-container_1 ... creating todoangularv2_express-container_1 ... done attaching todoangularv2_mongo-container_1, todoangularv2_express-container_1 mongo-container_1    | 2017-07-25t15:26:09.863+0000 control  [initandlisten] mongodb starting : pid=1 port=27017 dbpath=/data/db 64-bit host=25f03f51322b mongo-container_1    | 2017-07-25t15:26:09.864+0000 control  [initandlisten] db version v3.0.15 mongo-container_1    | 2017-07-25t15:26:09.864+0000 control  [initandlisten] git version: b8ff507269c382bc100fc52f75f48d54cd42ec3b mongo-container_1    | 2017-07-25t15:26:09.864+0000 control  [initandlisten] build info: linux ip-10-166-66-3 3.2.0-4-amd64 #1 smp debian 3.2.46-1 x86_64 boost_lib_version=1_49 mongo-container_1    | 2017-07-25t15:26:09.864+0000 control  [initandlisten] allocator: tcmalloc mongo-container_1    | 2017-07-25t15:26:09.864+0000 control  [initandlisten] options: {} mongo-container_1    | 2017-07-25t15:26:09.923+0000 journal  [initandlisten] journal dir=/data/db/journal mongo-container_1    | 2017-07-25t15:26:09.924+0000 journal  [initandlisten] recover : no journal files present, no recovery needed express-container_1  | listening on port 3000 express-container_1  | express-container_1  | events.js:72 express-container_1  |         throw er; // unhandled 'error' event express-container_1  |               ^ express-container_1  | error: failed connect [mongo-container:27017] 

so frontend cannot reach mongo container called 'mongo-container' in docker-compose file. in application i'm giving url mongo database follows:

module.exports = {     url : 'mongodb://mongo-container:27017/todo' } 

any idea how can change application when run on docker, don't have connectivity issue?

edit: mongo container gives following output:

wauterw-m-t3zt:vagrant wim$ docker logs f63 2017-07-26t09:15:02.824+0000 control  [initandlisten] mongodb starting : pid=1 port=27017 dbpath=/data/db 64-bit host=f637f963c87f 2017-07-26t09:15:02.825+0000 control  [initandlisten] db version v3.0.15 2017-07-26t09:15:02.825+0000 control  [initandlisten] git version: b8ff507269c382bc100fc52f75f48d54cd42ec3b ... 2017-07-26t09:15:21.461+0000 storage  [fileallocator] done allocating datafile /data/db/local.0, size: 64mb,  took 0.024 secs 2017-07-26t09:15:21.476+0000 network  [initandlisten] waiting connections on port 27017 

the express container gives following output:

wauterw-m-t3zt:vagrant wim$ docker logs 25a listening on port 3000  events.js:72         throw er; // unhandled 'error' event               ^ error: failed connect [mongo-container:27017]     @ null.<anonymous> (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:555:74)     @ eventemitter.emit (events.js:106:17)     @ null.<anonymous> (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15)     @ eventemitter.emit (events.js:98:17)     @ socket.<anonymous> (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)     @ socket.eventemitter.emit (events.js:95:17)     @ net.js:441:14     @ process._tickcallback (node.js:415:13) 

edit: issue appeared in dockerfile. here corrected 1 (simplified bit started node image rather ubuntu image):

from node:0.10.40 run mkdir -p /usr/src/app workdir /usr/src/app copy . /usr/src/app run npm install cmd ["node", "/usr/src/app/bin/www"] 

you substitute depends_on links session, express dependency between services depends_on and, according documentation, containers linked service reachable @ hostname identical alias, or service name if no alias specified.

version: '2' services:   express-container:     build: .     ports:      - "3000:3000"     links:      - "mongo-container"   mongo-container:     image: mongo:3.0 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -