
我正在嘗試使用 Visual Studio 2019 開發在 Docker for Windows 中運行的 ASP.NET Core 3.1 應用程式。我在這方面遇到了一些問題。我需要託管一個端點來啟動和停止服務並提供一些運行狀況檢查資訊。這些服務是從第三方 MSI 安裝的(我希望只是複製文件,但我們不想在不受支援的情況下運行它,加上它的文件和註冊表更改)。基本(dotnet/sdk、/core 和 /aspnet)映像是基於 Nano Server,因此不支援 MSI/msiexec。我嘗試了大量的圖像來找到一個支援 ASP.Net Core 和 msiexec(伺服器核心)的圖像,但似乎只有大圖像才能滿足我們的需求(8+ GB vs <500MB 的 Nano 圖像)。這裡還有另一種可能性嗎?此時,我什至無法讓構建持續工作。文件將構建,但不會最終出現在最終映像中,如果它們成功了,我似乎無法命中它們(嘗試端口 80/443、5000/5001 或實際的 Docker 公開端口,使用 localhost 或容器的 IP地址)。這變得非常令人沮喪!我很樂意提供任何幫助。
- 尋找支援 ASP.net Core 3.1 和 msiexec 的合理大小的映像
- 建立正確發布檔案並將檔案複製到最終映像的流程
- 可從容器外部存取服務。
目前的docker檔案:
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# INSTALL dotnet
ADD https://download.visualstudio.microsoft.com/download/pr/c37ece76-1305-4042-a9e6-58e7cb1b0bf6/75c20ff59335e370985b4f03fa637fcb/aspnetcore-runtime-3.1.18-win-x64.exe /symedical/
ADD https://download.visualstudio.microsoft.com/download/pr/7d09d7c0-8902-4467-9268-d7f584923cde/eddcb12257e68b030bc1b4baf9a68681/dotnet-runtime-3.1.18-win-x64.exe /symedical/
RUN C:/symedical/aspnetcore-runtime-3.1.18-win-x64.exe /install /quiet /norestart && \
C:/symedical/dotnet-runtime-3.1.18-win-x64.exe /install /quiet
ARG InstallerSrc="dist/installers/ThirdPartyClientServices.msi"
ARG InstallerDest="/install/"
ADD ${InstallerSrc} ${InstallerDest}
ARG InstallerSrc="dist/scripts/"
ADD ${InstallerSrc} ${InstallerDest}
RUN powershell -file "c:\dist\scripts\install-msi.ps1"
######
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["Distribution/Distribution.csproj", "Distribution/"]
RUN dotnet restore "Distribution/Distribution.csproj"
COPY . .
WORKDIR "/src/Distribution"
RUN dotnet build "Distribution.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Distribution.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Distribution.dll"]