I am building a project in MEAN stack. I have 4 different images: single angular-2 , 2 nodejs images (Say node-1 and node-2) and a single mongoDB image. I have linked the containers of the mentioned images with docker-compose.yml file and run the command docker-compose up. Now what happens is a network of those containers gets created. As per observation container of node-1 image can communicate with container of node-2 image and container of mongoDB image as well. But the container of angular-2 image is NOT ABLE to communicate with node container WITHIN THE NETWORK. But the container of the angular-2 image successfully communicates with the node containers through the URL exposed by the node container to host i.e. if API URL’s mentioned in angular code is mentioned as http:localhost:3000/myapi then it works. I am sharing a sample docker-compose.yaml file for better understanding.
#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: