Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Node JS Installation

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?

like image 743
user1200387 Avatar asked Aug 17 '15 02:08

user1200387


People also ask

What is docker node JS?

Docker allows you to package an application with its environment and all of its dependencies into a "box", called a container. Usually, a container consists of an application running in a stripped-to-basics version of a Linux operating system.


1 Answers

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.

like image 129
Angad Singh Avatar answered Oct 05 '22 11:10

Angad Singh