docker生成dotnet core镜像
使用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>