c# - 我可以进一步减少对由docker容器上的asp.net Web API应用程序运行的docker镜像的依赖性

标签 c# asp.net docker asp.net-web-api containers

我跟随https://github.com/Microsoft/dotnet-framework-docker链接在.net 4.6.1框架的顶部构建了示例ASP.NET Web API应用程序。

这是我的docker文件:

FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.sln .
COPY TestWebAPI/*.csproj ./TestWebAPI/
COPY TestWebAPI/*.config ./TestWebAPI/
RUN nuget restore

# copy everything else and build app
COPY TestWebAPI/. ./TestWebAPI/
WORKDIR /app/TestWebAPI
RUN msbuild /p:Configuration=Release


FROM microsoft/aspnet:4.7.2 AS runtime
WORKDIR /inetpub/wwwroot
COPY --from=build /app/TestWebAPI/. ./

要运行脚本,我执行以下命令:
docker image build --tag testwebapi --file .\Dockerfile .

docker container run --detach --publish 80 testwebapi

脚本运行正常,我能够运行我的应用程序。

问题:
  • 我正在使用dotnet-framework:4.7.2-sdk图像来构建&aspnet:4.7.2图像来运行应用程序。我查看了aspnet镜像,它包含“Windows Server Core作为基本操作系统,IIS 10作为Web服务器,.NET Framework(有多个版本),. NET IIS的可扩展性”。在这种情况下,我还需要dotnet-framework:4.7.2-sdk图片吗?

    enter image description here
  • 我不认为脚本使用IIS作为Web服务器。如何使用IIS托管此应用程序?
  • 最佳答案

    首先,请注意,sdk基本镜像实际上没有包含在最终镜像中,只有运行时镜像包含在其中。 FROM中有两条Dockerfile行:

    FROM microsoft/dotnet-framework:4.7.2-sdk AS build
    ...
    FROM microsoft/aspnet:4.7.2 AS runtime
    

    这将创建一个multi-stage build。只有第二(最后)阶段的基础镜像(即运行时镜像)将包括在镜像中。

    对于.NET Framework本身之外的sdk镜像中包含的内容,请查看其Dockerfile,您会发现生产服务器上绝对不需要的一些内容,例如NuGet CLI,VS Test Agent等。

    关于c# - 我可以进一步减少对由docker容器上的asp.net Web API应用程序运行的docker镜像的依赖性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53999565/

    相关文章:

    asp.net - Response.Redirect 与 Server.Transfer - 重定向为 "suggestion"

    docker - 在不旋转容器的情况下挤压 docker 镜像

    bash - Docker-文件中基于动态正则表达式的sed替换

    javascript - 如何在 asp.net c# 中注销我的应用程序?

    c# - 使用异常而不是冗长的空检查是否可以接受?

    javascript - Angular 在网页中没有显示任何内容,清楚地显示数组中的数据

    asp.net - 将 IIS 从经典模式切换到集成模式时的锁定和高 CPU 利用率

    php - Docker 中的 file_put_contents 权限

    c# - 删除文件夹 C# .net Core

    c# - 为什么 Visual Studio 向我的命名空间添加一个 at 符号 (@)?