docker生成dotnet core镜像

早过忘川 提交于 2020-12-17 07:28:55

使用docker生成dotnet core项目镜像。需要编写Dockerfile文件。编写方法有两种,如下:

第一种:将发布成功的项目,直接生成镜像。

FROM microsoft/dotnet:2.2-aspnetcore-runtime

WORKDIR /app
EXPOSE 5000

COPY bin/Debug/netcoreapp2.2/publish/ app/

ENV ASPNETCORE_URLS http://*:5000

ENTRYPOINT ["dotnet", "app/WebApplication1.dll"]

 

 

第二种:发布源码,自动build,publish

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 5000

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src

COPY . .

RUN dotnet restore "WebApplication1.csproj" --configfile NuGet.Config

WORKDIR "/src/"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .

ENV ASPNETCORE_URLS http://*:5000

ENTRYPOINT ["dotnet", "WebApplication1.dll"]

NuGet.Config文件内容

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://nuget.cdn.azure.cn/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!