ASP.NET Core容器化部署的方法通常使用Docker來實現。下面是一個簡單的步驟:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "YourProjectName.dll"]
docker build -t your-image-name .
docker run -d -p 8080:80 --name your-container-name your-image-name
現在你的ASP.NET Core應用已經成功部署到Docker容器中,并可以通過訪問 http://localhost:8080 來訪問。