16

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?

Roman
  • 19,581
  • 6
  • 68
  • 84
user1200387
  • 625
  • 2
  • 13
  • 22
  • 1
    Are you using it on Linux or boot2docker? – Roman Aug 17 '15 at 02:15
  • @R0MANARMY I am running the installation on my mac and followed the instructions in the link verbatim. It is launching on top of a centos image. Not sure if I answered your question but like I said I am completely new to docker so I might be confused on a lot of things associated with it. Never ran any boot2docker commands and also know that I am running something on virtualbox. The virtualbox does say that the OS is linux but mentions boot2docker in the SATA port. – user1200387 Aug 17 '15 at 02:25
  • It sounds like boo2docker isn't correctly forwarding `localhost` requests to the vm docker is running in. You could confirm that by getting the IP address of boo2docker vm from virtual box and trying to access your node website at *http://:49160*. If you get a response then it was just that localhost wasn't being forwarded to your VM, if not, then it's something else. – Roman Aug 17 '15 at 17:27
  • Have you finally solved your problem? I am pretty interested, because I run into the same error. – PDXIII Jun 17 '16 at 13:30

5 Answers5

13

This is the solution:

  1. 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

  2. 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>

  3. 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.

IAmInPLS
  • 4,051
  • 4
  • 24
  • 57
Angad Singh
  • 146
  • 2
  • In your case your running command will be docker run --rm -i -t -p 49160:8080 username/docker-test – Angad Singh Aug 23 '15 at 15:44
  • What else can I do, when this doesn’t solve my problem? Is there anything in the node-app actually which I have done wrong? – PDXIII Jun 17 '16 at 14:11
6

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
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
3

If you are using Mac OS X and have installed docker using Docker Toolbox, you can use:

    curl $(docker-machine ip default):49160
Gnana
  • 614
  • 1
  • 7
  • 18
2

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.

Nimix
  • 61
  • 3
  • Thanks for your reply, the logs displayed exactly what the tutorial said it would "Running on http://localhost:8080". When I login to the actual container and check for running processes it seems to look correct: [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. Is there any firewalls that could be causing issues? – user1200387 Aug 17 '15 at 11:56
2

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
Riddhi Gohil
  • 1,758
  • 17
  • 17