Node server on docker not accessible on localhost even after port binding

docker run port not accessible
docker localhost not working
docker port mapping not working
docker node http-server
docker run expose localhost port
docker nodejs
localhost 3000 docker
how to access port in docker

I have graphql node server. I am able to run it locally without docker. But after creating a docker container of the server and binding the container port with the host port this doesn't work.

Here's my Dockerfile code:

 FROM node:boron-alpine
 WORKDIR /app
 COPY package.json /app
 RUN npm install
 COPY . /app
 ENV SERVER_PORT 8080 
 EXPOSE 8080
 CMD npm run build && npm start

My node server code is as such :

  app.listen(process.env.SERVER_PORT,'0.0.0.0')
  console.log(`listening at ${port}`)

I run docker with the following command:

   docker run -it -p 8080:8080  nodeapi

This works perfectly nodejs can see the env SERVER_PORT cause it shows

   "listening at 8080"

in the console.

But when i open localhost:8080 this doesn't work (The site cannot be reached).

I have also tried running docker command

    docker run -it -p 127.0.0.1:8080:8080  nodeapi

This doesn't work

I am using docker toolbox on windows 10 latest build

Thank you

Docker toolbox doesn't map ports to localhost. It maps it to the Docker VM IP's

Run below command to get the IP

docker-machine ip

Then use the http://<IP>:8080 in your browser

node:8.15.1 cannot access https://localhost from host to container , Docker toolbox doesn't map ports to localhost. It maps it to the Docker VM IP's. Run below command to get the IP docker-machine ip. Then use the  localhost port binding will work from host to container on Windows Server 2016. Actual behavior. Does not work from host, other servers can access the port though. Information. Windows Version: Windows Server 2016 Standard Version 1607; Docker for Windows Version: 17.06.2-ee-10

If you avoid specifying the IP 0.0.0.0

app.listen(process.env.SERVER_PORT, function () {
   console.log('Listening on port '+ process.env.SERVER_PORT);
});

and

docker run -it -p 8080:8080  nodeapi

it will let you load the site as

http://localhost:8080

Docker running host but not accessible, Hi, I am trying to use node:8.15.1 version for SharePoint Framework development​. I use the following Dockerfile to create my image. however, when I @​frankchen76 you need to bind a host port to the container port at runtime. console.log msg) but no response when I request localhost or even 0.0.0.0. could not access port 80 from localhost. Trying to run docker run -p 8080:80 microsoft/iis result in no manifest for windows/amd64. I think in on the wrong version of docker-ee. Are there instructions to get the correct version of docker-ee onto windows server version 1803? Install commands were:

when you start the Docker using docker quickstart terminal, you can see the IP Address. (you can get to know the ip-address using the command "docker-machine ip" as well)

URL to access will be http://ip-address:portbinded

Can't connect to node HTTP server running on localhost , When I try to run the image it is displaying running on http://8000 but it is not in the localhost How to resolve that issue? docker file: FROM node:carbon # Creat​… server js: 'use strict'; const express = require('express'); // Constants “Binds​”: null, also, you did not map the port onto the host at all with -p. Someone proposes as a workaround to access <docker-machine ip>:<exposed port> instead of localhost:<exposed port>. Yes, that works but is not a solution. If I have a server in a Docker container, the docs say it can be accessed like localhost:80, but I have to first find the machine IP and go like `192.168.99.100:80'. That means it is in the

Connection refused? Docker networking and how it impacts your , I have graphql node server. I am able to run it locally without docker. But after creating a docker container of the server and binding the container port with the  Docker: Port not accessible even after being exposed. Posted on 8th March 2019 by morpheus. we created a docker container like this: docker container create --name

Dockerizing a Node.js web app, Can't connect to node HTTP server running on localhost on CircleCI I was also apparently able to launch the Node server on port 9000. for more details # version: 2 jobs: build: docker: # specify the version you desire I am not familiar with Yarn, but it looks to me that your server is called Gatsby, and  No, ClusterIP is a psudo address which can be used in POD network. It is not a node's address. And Node is the VM running on Hyper-V, not Windows host. You can confirm by "netstat.exe -na | findstr 31492" and "curl.exe NODEADDRESS:31492" on Windows host.

Consul with Containers, If you then try to connect with your browser to http://127.0.0.1:8000 you'll get How to fix your image so the server is accessible. python3 -m http.server --bind 127.0.0.1 Serving HTTP on 127.0.0.1 port 8000 (http://127.0.0.1:8000/) . Docker runs on non-Linux OSes like macOS by running a Linux virtual  Port binding is not working for me in TP5. Tried from a different host and same issue. Not sure whats wrong. netstat -an does not show any listening port after running docker run with port binding 80:80. docker inspect shows the below. PS C:\Windows\system32> docker inspect 4b145d28211d [

Comments
  • This works perfectly thanks. But is there a way to map it to localhost instead?.
  • docker-machine ip gives No machine name(s) specified and no "default" machine exist to me
  • @scroobius, you can map it to localhost by doing port forwarding in the VM settings
  • @StepanYakovenko, you are using docker for windows or docker toolbox? You can manually launch virtualbox and see the machine name. If there is none then that means you haven't initialised the default machine as well