Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

node.js - Docker container with Angular2 app and NodeJs does not respond

I created new Angular2 app by angular-cli and run it in Docker. But I cannot connect it from localhost.

At first I init app on my local machine:

ng new project && cd project &&  "put my Dockerfile there" && docker build -t my-ui .

I start it by command:

docker run -p 4200:4200 my-ui

Then try on my localhost:

curl localhost:4200

and receive

curl: (56) Recv failure: Connection reset by peer

Then, I tried switch into running container (docker exec -ti container-id bash) and run curl localhost:4200 and it works.

I also tried to run container with --net= host param:

docker run --net=host -p 4200:4200 my-ui

And it works. What is the problem? I also tried to run container in daemon mode and it did not helped. Thanks.

My Dockerfile

FROM node

RUN npm install -g angular-cli@v1.0.0-beta.24 && npm cache clean && rm -rf ~/.npm

RUN mkdir -p /opt/client-ui/src
WORKDIR /opt/client-ui  

COPY package.json /opt/client-ui/
COPY angular-cli.json /opt/client-ui/
COPY tslint.json /opt/client-ui/

ADD src/ /opt/client-ui/src

RUN npm install
RUN ng build --prod --aot

EXPOSE 4200

ENV PATH="$PATH:/usr/local/bin/"    
CMD ["npm", "start"]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems that you use ng serve to run development server and it by default starts on loop interface (available only on localhost). You should provide specific parameter:

ng serve --host 0.0.0.0

to run it on all interfaces.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...