Running Microservices in Docker

Search for a command to run...

No comments yet. Be the first to comment.
In this article, we'll write a JUnit Test configured with Environment Variables using junit-pioneer library. First of all, we need to add the junit-pioneer library and maven-surefire-plugin to the Maven pom.xml. <project> <properties> <p...
Problem The problem occurs when using the Python requests library, the chardet library is not installed. /Users/adacheng/Library/Python/3.9/lib/python/site-packages/requests/__init__.py:86: RequestsDependencyWarning: Unable to find acceptable charact...

Apache Kafka is an open-source distributed event streaming platform for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications. Introduction This article aims to provide basic hands-on instructions ...

Problem When AWS STS module is included in a Spring Boot Application, exception complaining region not set is thrown. Maven pom.xml <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>sts</artifactId> </dependency> Error M...

Installation Follow the instruction in this article to install Trivy. Scan To scan the docker image: Build the image. docker build . -t hello-world Scan the image. trivy scan hello-world

Today, I managed to run my microservices in docker environment successfully.
I have written four microservices using Spring Boot. One is Eureka Server and the other three are Eureka Clients.
| Docker Tag Name | Description | Port | Source Code Path |
| ms-server-eureka | Spring Boot Application acting as Eureka Discovery Server. | 8001 | $MS_SRC_BASE/ms.server.eureka/ |
| ms-client-user | Spring Boot Client Application connecting to MongoDB. | 8002 | $MS_SRC_BASE/ms.client.user/ |
| ms-client-product | Spring Boot Client Application connecting to MongoDB. | 8003 | $MS_SRC_BASE/ms.client.product/ |
| ms-client-cart | Spring Boot Client Application connecting to MongoDB. | 8004 | $MS_SRC_BASE/ms.client.cart/ |
| ms-mongodb | MongoDB | 27017 | NIL |
Firstly, create Dockerfile for each of the microservice.
Here below is the example for the User Microservice.
FROM openjdk:17-ea-22
COPY target/ms.client.user-0.0.1-SNAPSHOT.jar ms.client.user-SNAPSHOT.jar
EXPOSE 8001
ENTRYPOINT ["java","-jar","/ms.client.user-SNAPSHOT.jar"]
Secondly, build each of the Spring Boot Applications and package to JAR files.
./mvnw -Dmaven.test.skip=true clean package
Thirdly, build docker image of each of the Spring Boot Applications.
*Make sure Docker Engine is running on your development host.
cd $MS_SRC_BASE/ms.server.eureka/
docker build --tag=ms-server-eureka:latest .
cd $MS_SRC_BASE/ms.client.user/
docker build --tag=ms-client-user:latest .
cd $MS_SRC_BASE/ms.client.product/
docker build --tag=ms-client-product:latest .
cd $MS_SRC_BASE/ms.client.cart/
docker build --tag=ms-client-cart:latest .
--network container:[containerName] to bind to a master container. In this case, I use ms-server-eureka as the master container.docker run --name ms-server-eureka -p 8000-8003:8000-8003 -p 27017:27017 ms-server-eureka:latest
docker run --name ms-mongodb --network container:ms-server-eureka -d mongo
docker run --name ms-client-user --network container:ms-server-eureka ms-client-user:latest
docker run --name ms-client-product --network container:ms-server-eureka ms-client-product:latest
docker run --name ms-client-cart --network container:ms-server-eureka ms-client-cart:latest
Check the Eureka Server status by opening http://localhost:8000/ in a web browser.

Get data from the User Microservice by opening http://localhost:8001/user/search/findByLastName?name=Administrator in a web browser.
