Prasanna Prasanna - 1 year ago 71
Node.js Question

Dockerized Node js app does not start

After dockerizing my demo Express js app and starting the container, I am unable to access the service due to a

"Connection Timeout"

Url for the for project before dockerizing (Which produced "Hello world!" on the browser):


Url for the project after starting the docker container (Gives a " took too long to respond.")


FROM node:argon

# 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

CMD [ "node", "server.js" ]

I built my docker image like

docker build -t prasannarb/example-node-service

I started my docker image as a container like

docker run -t prasannarb/example-node-service

Then when I,
docker ps
, it gives me

7cf955f5d799 prasannarb/example-node-service "node server.js" About a minute ago Up About a minute 3000/tcp thirsty_perlman

docker inspect 7cf955f5d799
gives me
"IPAddress": ""

Since I did not explicitly give a port to start my container, I was assuming it would take the same as exposed by my docker container (3000) which is the same port where my service would listen too.

What am I doing wrongly here?

Answer Source

The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. EXPOSE does not make the ports of the container accessible to the host.

To do that, you must use either the -p flag

Your docker run command should look like this:

$docker run -p3000:3000 -t prasannarb/example-node-service

Additionally, the docker inspect command gave you the container IP address, not the host IP address.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download