TheReturningVoid
TheReturningVoid

Reputation: 111

Node.js web application not running properly in Docker stack

I have a web application written in Node.js that I'm trying to get into Docker. Running the image with docker run -p 80:80 image works just fine; I'm able to access the webpage it's hosting. However, when I try to run it in a stack, I'm unable to access the page, and Chrome just sits "Waiting for localhost..." forever.

Dockerfile:

FROM readytalk/nodejs

WORKDIR /app
ADD . /app

RUN npm i

EXPOSE 80

CMD []
ENTRYPOINT ["/nodejs/bin/npm", "start"]

docker-compose.yml:

version: "3"
services:
  web:
    image: image_name
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
    networks: 
      - webnet
networks:
  webnet:

Any help would be greatly appreciated.

EDIT: Added some logging and it seems that the HTTP request is never actually making it to the Node.js app. It seems like Docker has recieved the request, but hasn't routed it to the running app.

Upvotes: 0

Views: 351

Answers (1)

Adiii
Adiii

Reputation: 59896

  1. Some time your docker container run your IP address. you can check it by running this command docker info
  2. second option

Go to terminal and write

in window

ipconfig

and see preferred IP then access your container with that IP with specifying port

in Ubuntu

ifconfig

Hope this will solve your problem and try to access using 127.0.0.1:port

You can check this slide which shows and run hello world node+docker

docker-node-hello-world-application

And I will recommend using this Docker file.

Node_DockerFile

FROM alpine
RUN apk update && apk upgrade
RUN apk add nodejs
RUN mkdir -p /app
ADD app/package.json /app
WORKDIR /app/
ENV HOME /app
ENV NODE_ENV development
RUN npm install
ADD app /app    
EXPOSE 3000
CMD npm start

Upvotes: 1

Related Questions