Reputation: 15094
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.
Upvotes: 0
Views: 2327
Reputation: 15112
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
Upvotes: 1