In this series, I will build and deploy a simple microservice app with docker. Everything begin from scratch π
Prerequisite
Tech stack
Right here, I will use:
- FE: Angular
- BE: Java
- DB: MySQL
P/s: You can use your preferred stack, but scripting a docker-image
build may differ slightly.
Architecture
The system will have 6 components:
1) Client app: Interact BE via API
2) Nginx (gateway): Reverse proxy and load balancer
3) Project Service: Handle request relate to project
4) Task Service: Handle request relate to task
5) User Service: Handle request relate to user
6) Database Layer (MySQL): Data persistence
Project Structure
/
βββ client-app/
β βββ src/
β βββ Dockerfile
βββ project-service/
β βββ src/
β βββ Dockerfile
βββ task-service/
β βββ src/
β βββ Dockerfile
βββ user-service/
β βββ src/
β βββ Dockerfile
βββ docker-compose
βββ nginx.conf
βImportant thing: Did you notice every service have each own Dockerfile π€
Docker file
- FE (AngularJS)
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
COPY angular*.json ./
COPY tsconfig*.json ./
RUN npm install --legacy-peer-deps
COPY . .
RUN npm run build -- --configuration production
FROM nginx:alpine AS production
COPY --from=builder /app/dist/client-app/browser/ /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
- BE (Java)
FROM maven:latest AS build
WORKDIR /projectservice
COPY . .
RUN mvn clean package -DskipTests
FROM eclipse-temurin:21-jdk-alpine
WORKDIR /projectservice
COPY --from=build /projectservice/target/*.jar app.jar
EXPOSE 8081
ENTRYPOINT ["java", "-jar", "/projectservice/app.jar"]
As mentioned above, each service will have its own Dockerfile so remember clone and update it for each service.
Conclusion
Okay, I have an overview of the project and its functionality. In the next post, I'll delve into implementation details.
Happy Coding!!!
Top comments (0)