Reputation: 77
I'm dockerizing nodejs and mongoDB application but its not executing into browser.
This site can’t be reached
The connection was reset.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_RESET
By executing this command: docker-compose up --build
It will generates following output into ubuntu terminal.
web_1 | npm info lifecycle [email protected]~prestart: [email protected]
web_1 | npm info lifecycle [email protected]~start: [email protected]
web_1 |
web_1 | > [email protected] start /usr/src/app
web_1 | > node app.js
web_1 |
web_1 | App listning on port 3030
mongoDB_1 | 2017-05-16T07:07:27.891+0000 I NETWORK [initandlisten] connection accepted from 172.19.0.3:57655 #3 (1 connection now open)
FROM node:alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN npm install nodemon -g
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 3030
CMD [ "npm", "start" ]
version: "2.0"
services:
web:
build: .
command: npm start
ports:
- "3030:3000"
volumes:
- .:/api
links:
- mongoDB
mongoDB:
image: mongo:3.0
ports:
- "27017:27017"
volumes:
- /srv/docker/mongodb:/var/lib/mongodb
restart: always
{
"name": "test",
"version": "1.0.0",
"description": "My first node docker application",
"main": "index.js",
"dependencies": {
"express": "^4.15.2",
"mongodb": "^2.2.26"
},
"devDependencies": {},
"scripts": {
"start": "node app.js"
},
"author": "Muzammil",
"license": "ISC"
}
'use strict';
const express = require('express');
const app = express();
const MongoClient = require('mongodb').MongoClient;
const port = 3030;
let DB;
MongoClient.connect("mongodb://mongoDB/testDB", (err, db) => {
console.log(err);
//console.log(db);
DB = db;
});
app.get('/', (req, res)=>{
DB.collection("user").find({}, (err, result) => {
if(err) {
return res.json({message: "Error", error: err});
}
let results = [];
result.each((err, doc) => {
if(doc) {
console.log(doc);
}else {
res.end();
}
})
//res.status(200).json({message: "Successfully", code: 200, data: result});
});
});
app.listen(port, ()=>{
console.log(`App listning on port ${port}`);
});
Upvotes: 2
Views: 4974
Reputation: 4583
You have - "3030:3000" in your docker-compose file, which means you're trying to bind localhost port 3030 to the container port 3000. So, either expose port 3000, or change the line to - "3030:3030"
Upvotes: 6