简体   繁体   English

在 Linux Docker 中使用 .Net 标准库运行.Net Core 应用程序

[英]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!谢谢!

Quick Answer:快速回答:

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 标准库依赖项)并构建新映像

Explanation:解释:

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.

相关问题 .NET标准库的ASP.NET Core 2 Web应用程序参考 - ASP.NET Core 2 Web Application Reference to .NET Standard Library .Net核心应用程序不能在Linux上运行? - .Net core application cannot run on Linux? .net 标准库在 .net 核心中失败,但在框架中失败 - .net standard library fails in .net core but not in framework 我可以在Docker中运行现有的ASP.NET MVC应用程序而无需在Linux中转换为ASP.NET Core - Can I run existing ASP.NET MVC application in Docker without converting to ASP.NET Core in Linux .NET Core 1.1.4可以运行.NET standard 2吗? - Can .NET Core 1.1.4 run .NET standard 2? 无法在Linux Machine上为使用MySQL数据库和Pomelo.EntityFrameworkCore.MySql的点网核心2.1应用程序运行docker映像 - Cannot able to run a docker image on Linux Machine for dot net core 2.1 application which is using MySQL db with Pomelo.EntityFrameworkCore.MySql 如何在 docker 容器中运行 asp.net 核心应用程序? - How to run an asp.net core application in docker container? 如何通过docker通过启动配置文件运行.net核心应用程序 - How to run .net core application with launch profile via docker 从.net核心控制台应用程序引用.net标准2.0库中的dll时出错 - Error referencing dll in .net standard 2.0 library from .net core console application EF Core在.NET Standard vs .NET Core库中缺少任何内容吗? - Is EF Core missing anything in .NET Standard vs .NET Core library?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM