在博文(【Azure App Service For Container】建立ASP.NET Core Blazor項目並打包爲Linux鏡像發佈到Azure應用服務)中咱們經過VS 2019能夠爲項目添加Dockerfile並自動生成Docker Image文件。可是若是不借助於VS2019咱們如何來操做呢?html
進入項目文件夾中,建立Dockerfile並COPY如下內容:linux
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. #Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed. #For more information, please see https://aka.ms/containercompat FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build ENV ASPNETCORE_URLS=http://+:8000
WORKDIR /app EXPOSE 8000 EXPOSE 5000 COPY . /app/ ENTRYPOINT ["dotnet", "MyLife.Blazor.Server.dll"]
經過CMD進入到當前目錄, 使用 docker build -t mywebimages . (特別注意:在命令中必需要點.,黃色高亮的部分替代爲自定義的鏡像名。詳細的命令參考Docker說明:https://docs.docker.com/engine/reference/commandline/build/)web
當命令運行完成後,在Docker Desktop頁面中能夠看見當前Imagesdocker
在Docker Desktop中Run當前Image或者經過docker run命令啓動Container: docker run --name testweb -p 8080:8000 mywebimageswindows
命令啓動輸出:api
C:\MyCode\MyLife\MyLife.Blazor\MyLife.Blazor\Server\bin\Release\net5.0\publish>docker run --name testapidemo -p 8080:8000 mywebimages |
訪問Docker Container指定的端口8080結果爲:ide
Docker Hub: https://hub.docker.com/_/microsoft-dotnet-sdkpost
建立ASP.NET Core Blazor項目並打包爲Linux鏡像發佈到Azure應用服務: http://www.javashuo.com/article/p-dxzersbg-oa.htmlui
windows上用VS2019開發的 .NETCore項目如何打包部署到linux Docker中: https://blog.csdn.net/weixin_48000648/article/details/106524426