Network between Docker Microservices


1. Run two different microservices on docker
    Front-end: Angular 5 & Back-end: Spring Boot
2. Call Java API from the Front-end (container to container)


I've already posted how to Dockerize a Spring Boot application here

And I've also posted how to Dockerize an Angular Application here


Hola amigos,

In this post, we are going to use two different docker containers (one of them is back-end and the other one is front-end) and we will communicate via REST API between these two applications.

The overall picture will be like the diagram below

To do so, we need to find the IP address of the spring application and pass it to the front-end as API URL.

For the local env. we may use localhost: for the URL. 

So if we are running our spring boot application on localhost:8090 we can use that URL as the API URL.

We'll use this application as back-end:

This will be running on port 8090 so we need to change the front-end's API URL as localhost:8090

here you may find the whole project:

Build & run the both applications

Front-end (angular)
1. docker build -t fe-stock-angular .
2. docker run -i -t -p 8080:80 fe-stock-angular

Back-end (Spring Boot)
1. docker build . -t be-stock-springboot
2. docker run -i -p 8090:8090 -t be-stock-springboot

That's it! Now you have two different containers and the applications inside these containers are communicating via a REST API.

No comments: