0

I am new to Docker , so I may not be able to frame my question correctly.

I have created an image for my node js application by using below command.

 docker build -t ramakishore/nodeapp .

I have created a container for this image by executing below command

docker run -p 49160:8080 -d ramakishore/nodeapp

docker ps command displays

CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                     NAMES
ca64b61afca7        ramakishore/nodeapp   "npm start"         6 minutes ago       Up 6 minutes        0.0.0.0:49160->8080/tcp   gigantic_swanson

Contents of my dockerFile are

FROM node:boron

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app

EXPOSE 8080
CMD [ "npm", "start" ]

When I type http://localhost:8080 in chrome , I was expecting my node page to be displayed, but instead "This site can’t be reached" is displayed.

Any idea what is the mistake I doing.

4
  • 2
    localhost:49160 is your port... Commented Jan 13, 2017 at 8:16
  • for localhost:49160 also same issue.. Commented Jan 13, 2017 at 8:21
  • What enviroment are you on? Are you using docker for windows or docker on windows. If you are using docker on windows you will have a virtual mashine in virtualbox, and then you won't be able to reach localhost, then you will need to go to the adress of the virtual mashine Commented Jan 13, 2017 at 8:41
  • I am using docker toolbox for windows. Commented Jan 13, 2017 at 8:46

1 Answer 1

1

First I would check to see if your application is running inside your docker container by entering the container and looking at what is running:

$ docker exec -ti ca64b61afca7
$ ps aux

Then check to make sure it's listening on the correct port (and on 0.0.0.0):

$ netstat -tunlp

Next I would try a curl from inside the container:

$ curl localhost:8080

If this works, your app is running correctly and the issue lies between your container and your host.

Next I would exit the docker container (ctrl + d) and try to hit the app from the host:

$ curl localhost:49160

Note: If you're on a Mac or Windows, you may need to hit the IP address of the docker host - you can find this IP by doing an echo $DOCKER_HOST (or on Windows echo %DOCKER_HOST%.

E.g., if your DOCKER_HOST is 192.168.1.50 you would do a:

curl 192.168.1.50:49160
Sign up to request clarification or add additional context in comments.

1 Comment

using "ip" instead of "localhost" helped , now it's working...thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.