What I'm trying?
I'm trying to run my nodejs app inside a docker container and want to use it outside of the container(through my browser on port 3000).
DockerFile
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
RUN npm run build
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
app.ts(Relevant portion)
const port = process.env.port || 3000;
let app = express();
app.listen(port, () => {
console.log(`Listening on port ${port}!`);
});
command I'm using to run
$ docker run --net=host <imgName>
OS --> Windows 7
And in the Oracle Virtual Box I've changed network settings to bridged networks.
The command runs successfully and the server starts listening on port 80. And I can access it from outside the container on port 80 through postman,curl,browser,etc.
Where I am doing wrong? How can I make it to listen on port 3000? And also how is it even able to listen on port if I haven't exposed it explicitly?
I think the docker is passing port as an environment variable and setting it to 80 as I am not passing any environment variable myself.
Please help I'm very new to docker.