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

前端 未结 2 807
长情又很酷
长情又很酷 2020-12-11 13:42
My environment:
Ubunut 17.04 LTS
npm --version: 5.6.0
nodejs --version: 4.7.2
angular cli version: 1.6.4

docker-compose file:

versi         


        
相关标签:
2条回答
  • 2020-12-11 14:01

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

    services:
      node:
       ports:
         - 4200:4200
    
    0 讨论(0)
  • 2020-12-11 14:08

    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"]
    
    0 讨论(0)
提交回复
热议问题