ตอนแรกที่ทำ Blazer ผมเข้าใจว่าตอน Pack เป็น Container มันใช้ Dockerfile ทำ Multi-Stage แบบปกติตามนี้แหละ
# Stage 1: Build FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /src # Copy solution and project files COPY . . # Restore as distinct layer RUN dotnet restore FinancialChatBotBlazerUI/FinancialChatBotBlazerUI.csproj WORKDIR /src/FinancialChatBotBlazerUI RUN dotnet publish -c Release -o /app/publish --no-restore # Stage 2: Runtime FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final WORKDIR /app COPY --from=build /app/publish . EXPOSE 8080 ENTRYPOINT ["dotnet", "FinancialChatBotBlazerUI.dll"]
ปรากฏว่า มันรันได้ แต่ไม่มีหน้าเว็บออกมาเลย ซึ่งมันผิดวิธีครับ Blazer WASM มัน Run ที่ Client เหมือนพวก html javascript นี้แหละ เลยต้องใช้ท่าทำ container พวกเอา frontend ไปใส่ โดยใช้
- nginx
# Stage 1: Build FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /src # Copy solution and project files COPY . . # Restore as distinct layer RUN dotnet restore WORKDIR /src/FinancialChatBotBlazerUI RUN dotnet publish -c Release -o /app/publish --no-restore # Stage 2: Runtime # Serve Stage FROM nginx:alpine AS final WORKDIR /usr/share/nginx/html COPY --from=build /app/publish/wwwroot . COPY /FinancialChatBotBlazerUI/nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 8080 CMD ["nginx", "-g", "daemon off;"]
- default.conf - ให้มันสนใจ port ที่เรากำหนด เคสนี้ 8080 (ล้อกับ container) และให้มันพยายามหาของจาก /usr/share/nginx/html ถ้าไม่เจอค่อยบอก 404
server {
listen 8080;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html =404;
}
}ตัวอย่างเต็มๆ ลองแงะจาก repo นี้ได้ครับ https://github.com/pingkunga/semantic-kernel-financial-plugin-sample/tree/feature/sk2ag
Discover more from naiwaen@DebuggingSoft
Subscribe to get the latest posts sent to your email.



