5 传统.NET 4.x应用容器化( 二 )


3 pull & run
拉取一些基础镜像
这里我们还是拉取一些如.NET SDK & Runtime之类的基础镜像:
docker pull mcr.microsoft.com/dotnet/framework/sdk:4.8docker pull mcr.microsoft.com/dotnet/framework/aspnet:4.8构建ASP.NET应用镜像
这里我们将之前的asp.net mvc sample源码拷贝到Windows Server并进行build镜像 。
该源码的Dockerfile如下:
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS buildWORKDIR /app# copy csproj and restore as distinct layersCOPY *.sln .COPY aspnetmvcapp/*.csproj ./aspnetmvcapp/COPY aspnetmvcapp/*.config ./aspnetmvcapp/RUN nuget restore# copy everything else and build appCOPY aspnetmvcapp/. ./aspnetmvcapp/WORKDIR /app/aspnetmvcappRUN msbuild /p:Configuration=Release -r:FalseFROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 AS runtimeWORKDIR /inetpub/wwwrootCOPY --from=build /app/aspnetmvcapp/. ./构建过程如下:
E:\Sources\aspnetmvcapp> docker build -t reg.edisonzhou.cn/dotnet/samples:aspnetmvcapp .Sending build context to Docker daemon2.83MBStep 1/12 : FROM reg.edisonzhou.cn/dotnet/sdk:4.8 AS build ---> cf61fa19d693Step 2/12 : WORKDIR /app ---> Running in 0aeaf13a2399Removing intermediate container 0aeaf13a2399 ---> cd8cb2e21d9aStep 3/12 : COPY *.sln . ---> 720986cc9a80Step 4/12 : COPY aspnetmvcapp/*.csproj ./aspnetmvcapp/ ---> 19ed4b0394b8Step 5/12 : COPY aspnetmvcapp/*.config ./aspnetmvcapp/ ---> 685d35ea2682Step 6/12 : RUN nuget restore ---> Running in a96b4ac5f72c ......... 此处省略一万字 Removing intermediate container a3f263c97c1e ---> 40774beabb8cStep 10/12 : FROM reg.edisonzhou.cn/dotnet/runtime:4.8 AS runtime ---> 142ad6e5e9c6Step 11/12 : WORKDIR /inetpub/wwwroot ---> Running in e306e8160570Removing intermediate container e306e8160570 ---> 56f50e22d843Step 12/12 : COPY --from=build /app/aspnetmvcapp/. ./ ---> 313613c96b44Successfully built 313613c96b44Successfully tagged reg.edisonzhou.cn/dotnet/samples:aspnetmvcapp运行ASP.NET应用容器
直接通过 docker run 起来:
docker run --name aspnet_mvc_sample --rm -it -d -p 8000:80 --cpus 1 -m 1024m reg.edisonzhou.cn/dotnet/samples:aspnetmvcapp运行效果如图:

5 传统.NET 4.x应用容器化

文章插图
4 总结
本文介绍了如何在本地的Windows Server 2019服务器上安装和配置Docker环境,最后演示了一下ASP.NET应用的基本容器操作 。
对于传统.NET 4.x应用的容器化迁移,我们也还在探索,相信探索和实践的深入,我会分享更多相关的内容 。


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: