gpt4 book ai didi

c# - Docker 无法执行,因为找不到应用程序或未安装兼容的 .NET SDK

转载 作者:行者123 更新时间:2023-12-02 23:15:28 26 4
gpt4 key购买 nike

我正在尝试部署 .NET 5 控制台应用后台服务以在 Linux Azure VM 上的 Docker Linux 容器中运行。最终结果是容器立即退出,log显示:

Could not execute because the application was not found or acompatible .NET SDK is not installed. Possible reasons for thisinclude: * You intended to execute a .NET program:The application 'FileProcessSvcPOC.dll' does not exist. * You intended to execute a .NET SDK command:It was not possible to find any installed .NET SDKs.

我遵循的过程是使用 docker compose 与虚拟机的远程上下文。我还尝试将容器推送到 Azure 存储库并以这种方式部署(无需撰写)并得到相同的错误。

Docker 构建输出(没有显示错误):

=> [internal] load build definition from Dockerfile
0.2s => => transferring dockerfile: 778B 0.1s => [internal] load .dockerignore 0.1s => => transferring context: 35B 0.1s => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0 0.1s => [internal] load metadata for mcr.microsoft.com/dotnet/runtime:5.0
0.2s => [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:5.0@sha256:081a6c31153f16c02eeb7f1ad663adb8e1d21fa0d59402348c13bba7659a54190.0s => [base 1/2] FROM mcr.microsoft.com/dotnet/runtime:5.0@sha256:d78f83397086556adecb7d5b9e86751b9b591ffc7c17addaa55109b733cd0f500.0s => [internal] load build context 0.1s => => transferring context: 863B 0.1s => CACHED [base 2/2] WORKDIR /app 0.0s => CACHED [final 1/2] WORKDIR /app 0.0s => CACHED [build 2/7] WORKDIR /src 0.0s => CACHED [build 3/7] COPY [FileProcessSvcPOC/FileProcessSvcPOC.csproj, FileProcessSvcPOC/]
0.0s => CACHED [build 4/7] RUN dotnet restore "FileProcessSvcPOC/FileProcessSvcPOC.csproj"
0.0s => CACHED [build 5/7] COPY . . 0.0s => CACHED [build 6/7] WORKDIR /src/FileProcessSvcPOC 0.0s => CACHED [build 7/7] RUN dotnet build "FileProcessSvcPOC.csproj" -c Release -o /app/build
0.0s => CACHED [publish 1/1] RUN dotnet publish "FileProcessSvcPOC.csproj" -c Release -o /app/publish
0.0s => CACHED [final 2/2] COPY --from=publish /app/publish . 0.0s => exporting to image 0.1s => => exporting layers 0.0s => => writing image sha256:04297f1fb6c30fefb6e39005404b868bb8fd740a30de2174ea42780e16120ca70.0s => => naming to docker.io/library/fileprocesssvcpoc

Dockerfile:

FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["FileProcessSvcPOC/FileProcessSvcPOC.csproj", "FileProcessSvcPOC/"]
RUN dotnet restore "FileProcessSvcPOC/FileProcessSvcPOC.csproj"
COPY . .
WORKDIR "/src/FileProcessSvcPOC"
RUN dotnet build "FileProcessSvcPOC.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "FileProcessSvcPOC.dll"]

docker-compose.yml:

version: '3.4'

services:
fileprocesssvcpoc:
image: ${DOCKER_REGISTRY-}fileprocesssvcpoc
build:
context: .
dockerfile: FileProcessSvcPOC/Dockerfile

控制台应用程序Program.cs CreateHostBuilder

    public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSystemd()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<FileListenerSvc>();
services.Configure<AppSettings>(hostContext.Configuration.GetSection("AppSettings"));
});

*我读到的关于在 Linux 上部署 .NET 后台服务的文章说要使用 UseSystemd()。

我已使用 Docker 上下文/组合将 .NET 5 Web 应用程序部署到同一个 Linux VM,并且运行良好。

知道为什么上面的控制台应用程序设置会退出并出现错误,提示 .NET SDK 在 DockerFile 中引用并显示在构建输出中时未安装吗?

最佳答案

Matt Thalman 在评论我的问题时提供的命令显示该应用程序正在作为不带 dll 的 .exe 发布到容器。

更改发布选项以生成 dll 解决了该问题。

关于c# - Docker 无法执行,因为找不到应用程序或未安装兼容的 .NET SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69036186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com