Network between Docker Microservices


Steps

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)

-----
Prerequisites

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

https://www.nurettinyakit.com/2018/11/how-dockerize-spring-boot-java.html

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

https://www.nurettinyakit.com/2018/12/how-to-dockerize-angular-7-app.html

------

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: https://github.com/NurettinYAKIT/nurettinyakit.com/tree/master/be-stock-springboot

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: https://github.com/NurettinYAKIT/nurettinyakit.com/tree/master/fe-stock-angular

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: