[英]Run .Net Core application with .Net Standard library in Linux Docker
I have a.Net Core 3.1.200 that reference another code that is written in.Net Standard 1.3 (shared with.Net Framework apps).我有一个.Net Core 3.1.200,它引用了另一个用.Net Standard 1.3(与.Net Framework 应用程序共享)编写的代码。
When I try to push image to a docker it fails on all sorts of memory faults.当我尝试将图像推送到 docker 时,它会因各种 memory 故障而失败。 Image was running perfectly till the reference was added.
在添加参考之前,图像运行良好。 Here is my docker file:
这是我的 docker 文件:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1
COPY bin/publish/ /app-docker-image
WORKDIR /app-docker-image
ENTRYPOINT ["dotnet", "app.dll"]
Is there a way to make it work on a Linux docker?有没有办法让它在 Linux docker 上工作?
Thanks!谢谢!
Reference the project in your custom .net app.在您的自定义 .net 应用程序中引用该项目。 Transfer the app code (along with .NET standard lib dependency inside docker) and build the new image
传输应用程序代码(连同 docker 内的 .NET 标准库依赖项)并构建新映像
Your current approach isn't the recommended way of creating container images.您当前的方法不是创建容器映像的推荐方法。 You don't copy a pre-built code to the runtime image.
您不会将预构建的代码复制到运行时映像。
Rather than copying publish folder from host to container, you should transfer the code to the SDK container image.与其将发布文件夹从主机复制到容器,不如将代码传输到 SDK 容器映像。
With the code inside docker run dotnet CLI commands to build/publish the code.使用 docker 中的代码运行 dotnet CLI 命令来构建/发布代码。
The transfer the published folder from SDK container to runtime container.将发布的文件夹从 SDK 容器转移到运行时容器。 Your docker file should look like below:
您的 docker 文件应如下所示:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. #请参阅https://aka.ms/containerfastmode以了解 Visual Studio 如何使用此 Dockerfile 构建映像以加快调试速度。
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base WORKDIR /app FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["ConsoleApp1/ConsoleApp1.csproj", "ConsoleApp1/"]
RUN dotnet restore "ConsoleApp1/ConsoleApp1.csproj"
COPY . .
WORKDIR "/src/ConsoleApp1"
RUN dotnet build "ConsoleApp1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ConsoleApp1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp1.dll"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.