0

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.

3
  • have you tried it without the separate network? if this won't allow you to access the page, I'd remove the deploy settings as well. when you can access the page, you can add it back one by one, to see which one causes the troubles Commented Jun 10, 2017 at 7:48
  • @ShabbY Neither removing the network nor the deploy settings works, the browser still just waits infinitely. Commented Jun 10, 2017 at 7:52
  • hmm... here´s a Dockerfile I use for deploying a node project: github.com/Sh4bbY/node/blob/master/Dockerfile maybe this could help you Commented Jun 10, 2017 at 7:59

1 Answer 1

1
  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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, the second option worked for me. Still confused as to why the ports didn't bind to localhost like they do when I run a single container though.

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.