Docker Node JS Installation
Asked Answered
H

5

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?

Happening answered 17/8, 2015 at 2:10 Comment(4)
Are you using it on Linux or boot2docker?Everyone
@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.Happening
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://<ip address>: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.Everyone
Have you finally solved your problem? I am pretty interested, because I run into the same error.Puckery
U
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.

Uvulitis answered 23/8, 2015 at 15:42 Comment(2)
In your case your running command will be docker run --rm -i -t -p 49160:8080 username/docker-testUvulitis
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?Puckery
S
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
Snippet answered 17/2, 2017 at 15:8 Comment(0)
H
3

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

    curl $(docker-machine ip default):49160
Haldes answered 8/2, 2016 at 22:18 Comment(0)
A
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.

Abatement answered 17/8, 2015 at 5:41 Comment(1)
Thanks for your reply, the logs displayed exactly what the tutorial said it would "Running on 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?Happening
F
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
Forty answered 1/4, 2016 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.