dockerfile - Docker Container Failed to Run -
the dockerfile application follows
# tells docker base image start. node # adds files host file system docker container. add . /app # sets current working directory subsequent instructions workdir /app run npm install run npm install -g bower run bower install --allow-root run npm install -g nodemon #expose port allow external access expose 9000 9030 35729 # start mean application cmd ["nodemon", "server.js"]
the docker-compose.yml file follows
web: build: . links: - db ports: - "9000:9000" - "9030:9030" - "35729:35729" db: image: mongo:latest ports: - "27017:27017"
and error generated while running follows:-
web_1 | [nodemon] 1.11.0 web_1 | [nodemon] restart @ time, enter `rs` web_1 | [nodemon] watching: *.* web_1 | [nodemon] starting `node server.js` web_1 | server running @ http://127.0.0.1:9000 web_1 | server running @ https://127.0.0.1:9030 web_1 | web_1 | /app/node_modules/mongodb/lib/server.js:261 web_1 | process.nexttick(function() { throw err; }) web_1 | ^ web_1 | mongoerror: failed connect server [localhost:27017] on first connect web_1 | @ pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35) web_1 | @ emitone (events.js:96:13) web_1 | @ pool.emit (events.js:188:7) web_1 | @ connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:271:12) web_1 | @ connection.g (events.js:291:16) web_1 | @ emittwo (events.js:106:13) web_1 | @ connection.emit (events.js:191:7) web_1 | @ socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:165:49) web_1 | @ socket.g (events.js:291:16) web_1 | @ emitone (events.js:96:13) web_1 | @ socket.emit (events.js:188:7) web_1 | @ emiterrornt (net.js:1281:8) web_1 | @ _combinedtickcallback (internal/process/next_tick.js:74:11) web_1 | @ process._tickcallback (internal/process/next_tick.js:98:9) web_1 | [nodemon] app crashed - waiting file changes before starting...
i have uploaded image application @ dockerhub crissi/airlineinsurance.
in docker can't connect other container via localhost because each container independend , has own ip. should use container_name:port
. in example should db:27017
connect nodejs application in 'web' mongodb in 'db'.
so it's not problem of dockerfile. it's connection url nodejs application points localhost instead of db.
Comments
Post a Comment