when I map the port
docker run -d -p 8088:8088 nitikishu/samplenodejs
http://192.168.99.100:8088/ site is not reaching somtimes…
If I map with some other port it is working correctly…
docker run -d -p 8089:8088 nitikishu/samplenodejs
or
docker run -d -p 9191:8088 nitikishu/samplenodejs
It is running on the docker host.
But Now I used -p 8088:8088 for map. application is running. but unable to login
My question is my dockerfile and server.js file has port number as 8088 only, and also mongodb which I connect is my local db only.
env.config file
MONGODB_URI=mongodb://localhost:27017/sample_DB
SESSION_SECRET=sample
App_PORT = 8088
From that env file I am taking the MONGODB_URI into server.js
server.js
var express = require(‘express’);
var session = require(‘express-session’);
const bodyParser = require(‘body-parser’);
const logger = require(‘morgan’);
const chalk = require(‘chalk’);
const errorHandler = require(‘errorhandler’);
const dotenv = require(‘dotenv’);
const path = require(‘path’);
const mongoose = require(‘mongoose’);
const MongoStore = require(‘connect-mongo’)(session);
const passport = require(‘passport’);
const expressValidator = require(‘express-validator’);
var app = express();
var multer = require(‘multer’);
var request = require(‘request’);
var fs = require(‘fs’)
dotenv.load({ path: ‘.env.Config’ });
app.use(express.static(__dirname + “/public”));
app.set(‘views’, __dirname + ‘\public’);
app.engine(‘html’, require(‘ejs’).renderFile);
app.set(‘view engine’, ‘html’);
app.use(bodyParser.json());
mongoose.connect(process.env.MONGODB_URI);
mongoose.connection.on(‘error’, () => {
console.log(‘%s MongoDB connection error. Please make sure MongoDB is running.’, chalk.red(‘✗’));
process.exit();
});
app.set(‘port’, process.env.App_PORT || 3000);
app.listen(app.get(‘port’), () => {
console.log(‘%s server running on port’, chalk.green(‘✓’), app.get(‘port’));
console.log(’ Press CTRL-C to stop\n’);
});
I do know this port 8088 is mismatching with 9191 ? if so How to do rectify?
Another doubt is in my env file, I am just passing localhost mongodb path
I may think due to this, My application is showing error while login. because login credentials username and password is checking the db. Entered username and password is already exists for that user or not.
if the username and password is correct I am just redirecting/login to the application. otherwise I am showing error message. But this is not happening… May be it is due to that host address right.?
Can you clarify that error and correct the problem?