Reputation: 625
I am brand new to docker and I am attempting to follow the node js tutorial that they have listed: https://docs.docker.com/examples/nodejs_web_app/
I follow this tutorial and everything seems to work great until the test portion and I can't curl to the port specified.
$ curl -i localhost:49160
curl: (7) Failed to connect to localhost port 49160: Connection refused
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21e727bc5a7d username/docker-test "node /src/index.js" 13 minutes ago Up 13 minutes 0.0.0.0:49160->8080/tcp gloomy_heisenberg
$ docker logs 21e727bc5a7d
Running on localhost:8080
$ docker exec -it 21e727bc5a7d bash
[root@21e727bc5a7d /]# netstat -tulpn
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1/node'
Not sure if I am confused about something or how to troubleshoot this, any ideas?
Upvotes: 16
Views: 2789
Reputation: 61
I experienced the same problem and discovered it was due to boot2docker
not forwarding my localhost to the virtual machine in which Docker is running.
Find out the IP of the VM running Docker like so:
$ boot2docker ip
You'll see output like:
$ 192.168.99.102
And with the printout it gives you, curl your specified port on that IP. For example:
$ curl -i 192.168.99.102:49160
Upvotes: 6
Reputation: 146
This is the solution:
Run you application like this:
docker run --rm -i -t -p 49160:8080 <your username>/centos-node-hello
An output should come saying listening to port 8080. This means that the application is running
Open another docker CLI terminal and type:
docker-machine ls
You will see and IP address and a port. Example: 192.168.99.100:<some-number>
Go to a browser and type the IP address and the exported port number.
In this case, 192.168.99.100:49160
, and your website should come on.
Hope it helps.
Upvotes: 13
Reputation: 1818
Hit given command to find IP address of docker-machine
$ docker-machine ls
The output will be like :
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.10.3
Now run your application from host machine as :
$ curl -i 192.168.99.100:49160
Upvotes: 2
Reputation: 614
If you are using Mac OS X and have installed docker using Docker Toolbox, you can use:
curl $(docker-machine ip default):49160
Upvotes: 3
Reputation: 61
I can tell you how to troubleshoot this issue at least.
First check the logs, you'll need the container id to do this. You get the id of the container using docker ps
Run docker <id> logs
to view the logs. It's possible your command returned an error.
If you'd like to get a closer look, You can start a BASH shell on the container. Run this command docker exec -it <id> bash
and that will give you a shell on the container to troubleshoot. The shell is the same instance of the container so you can troubleshoot the running service.
Upvotes: 2