Pages - Menu

2022年11月22日 星期二

[Net].net core 打包dockerfile

碎碎念

今天才知道vistual studio 的神奇地方,
直接滑鼠按一按,dockerfile就自動產生了,
也不用寫,不過不是vs code的版本。


正文

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
RUN apt-get update -y && apt-get install -y libc6-dev libgdiplus libx11-dev && apt-get clean && ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ./**/*.csproj ./
# RUN pwd && ls -ahl
RUN for file in $(ls *.csproj); do mkdir -p ./${file%.*}/ && mv $file ./${file%.*}/; done
# RUN pwd && ls SystemManageService.Backend -ahl
RUN dotnet restore SystemManageService.Backend/SystemManageService.Backend.csproj

COPY . .
RUN dotnet build SystemManageService.Backend/SystemManageService.Backend.csproj -c Release -o /app/build



FROM build AS publish
RUN dotnet publish SystemManageService.Backend/SystemManageService.Backend.csproj -c Release -o /app/publish



FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
RUN ls

這邊的重點在這兩段,取得專案內所有的csproj,然後丟進去build的image裡面。
但是,這樣並不會根據資料夾放到其他特定的地方,
所以才有for file建立資料夾跟移動檔案。

COPY ./**/*.csproj ./
# RUN pwd && ls -ahl
RUN for file in $(ls *.csproj); do mkdir -p ./${file%.*}/ && mv $file ./${file%.*}/; done

ref. .NET Core Docker 再也不用逐個 COPY csproj 檔案啦!

沒有留言:

張貼留言