链接angular2应用程序容器与Nodejs容器

我在MEAN堆栈中build立一个项目。 我有4个不同的图像:单个angular度-2,2个nodejs图像(节点1和节点2)和一个单一的mongoDB图像。 我已经把提到的图片的容器和docker-compose.yml文件连接起来,然后运行docker-compose命令。

现在发生了什么是这些容器的networking被创build。 根据node-1映像的观察容器,也可以与node-2映像的容器和mongoDB映像的容器进行通信。 但是angular度2图像的容器不能与networking中的节点容器通信。 但是,angular-2映像的容器通过节点容器暴露的URL成功与节点容器进行通信,即如果在angular码中提到的API URL被称为http:localhost:3000 / myapi,那么它就起作用。

我正在分享示例docker-compose.yaml文件以便更好地理解:

version: "2" services: node-1: image: node-1-image ports: - "4000:4000" links: - mongoDB networks: - webnet node-2: image: node-2-image ports: - "3000:3000" links: - mongoDB - node-1 networks: - webnet client: image: angular-2 ports: - 80:80 networks: - webnet links: - node-1 - node-2 mongoDB: image: mongo ports: - "27017:27017" volumes: - "/data/db:/data/db" networks: - webnet networks: webnet: