I am trying to run a Node.js app on docker. I am using WSL and have successfully run the app on docker. Now the problem is that when I try to access the app on the browser, it's showing as no response. I can't access it in the browser. I also have another Reactjs app running on the docker and I can access that app through the browser. What am I doing wrong? Why Nodejs app is not accessible in the windows browser? Below is the Dockerfile for Node.js
# pull official base image
FROM node:12.18.3-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install --silent
# add app
COPY . ./
# start app
CMD ["npm", "run", "dev"]
Below is the command used for running the app image in docker
docker build -t gdns/node-app .
winpty docker run \
-it \
--rm \
-v ${PWD}:/app \
-v /app/node_modules \
-p 4000:4000 \
-e CHOKIDAR_USEPOLLING=true \
gdns/node-app
Node.js app is running, I can view the log as below

Please help
I have changed the code in the Node.js app to listen on "0.0.0.0".
const hostname = '0.0.0.0';
const port = 4000;
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With