nodejs app doesn't connect to localhost when running within a docker container

六眼飞鱼酱① 提交于 2019-11-28 13:12:51

Ok, as you say in your question, your process is listening to connection on localhost:4200.

Inside a docker container, localhost is the address of the loopback device of the container itself, which is separated and not reachable from your host network.

You need to edit your node process in order to make it listen to all addresses by editing the entrypoint in your Dockerfile as follows:

ENTRYPOINT ["ng", "serve", "-H", "0.0.0.0"]

In your docker-compose file, make sure to export the ports:

services:
  node:
   ports:
     - 4200:4200
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!