gpt4 book ai didi

docker - 使用 dotnet :2. 1-sdk 在 docker 容器中构建 dotnet 失败

转载 作者:行者123 更新时间:2023-12-04 19:27:57 25 4
gpt4 key购买 nike

我正在尝试向现有的 ASP.NET Core 2.1 Web 应用程序添加 docker 支持。它在 dotnet build 期间失败命令,说它无法加载共享库 kernel32.dlllibkernel32.dll .我有以下 Dockerfile

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY . .
RUN ls -la
WORKDIR /src/WebRazorPages
RUN ls -la
RUN dotnet restore -nowarn:msb3202,nu1503
RUN dotnet build --no-restore -c Release -o /app

FROM build AS publish
RUN dotnet publish --no-restore -c Release -o /app

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

它运行到 dotnet 构建步骤而没有错误,但随后失败,并在目标文件构建过程中出现查找共享文件的问题。完整输出如下所示:
1>------ Build started: Project: WebRazorPages, Configuration: Release Any CPU ------
1>You are working with a preview version of the .NET Core SDK. You can define the SDK version via a global.json file in the current project. More at https://go.microsoft.com/fwlink/?linkid=869452
1>docker exec -i 44ded24c4cef1fbf9539449dac737aa39e7c255d6a4da9f09106fb689be2a769 /bin/bash -c "if PID=$(pidof -x dotnet); then kill $PID; fi"
1>WebRazorPages -> C:\dev\github\eShopOnWeb\src\WebRazorPages\bin\Release\netcoreapp2.1\Microsoft.eShopWeb.RazorPages.dll
1>WebRazorPages -> C:\dev\github\eShopOnWeb\src\WebRazorPages\bin\Release\netcoreapp2.1\Microsoft.eShopWeb.RazorPages.Views.dll
1>docker build -f "C:\dev\github\eShopOnWeb\src\WebRazorPages\Dockerfile" -t microsoft.eshopweb.razorpages "C:\dev\github\eShopOnWeb\src"
1>Sending build context to Docker daemon 35.46MB
1>
1>Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
1> ---> 083ca6a642ea
1>Step 2/17 : WORKDIR /app
1> ---> Using cache
1> ---> b0c93ee1eca8
1>Step 3/17 : EXPOSE 80
1> ---> Using cache
1> ---> 76e2ed0decb7
1>Step 4/17 : FROM microsoft/dotnet:2.1-sdk AS build
1> ---> 1f63052e44c2
1>Step 5/17 : WORKDIR /src
1> ---> Using cache
1> ---> 1c80bb67fe43
1>Step 6/17 : COPY . .
1> ---> d97c2bf3a900
1>Step 7/17 : RUN ls -la
1> ---> Running in ecb2727f2649
1>total 24
1>drwxr-xr-x 1 root root 4096 May 21 14:37 .
1>drwxr-xr-x 1 root root 4096 May 21 14:37 ..
1>drwxr-xr-x 9 root root 4096 May 19 19:11 ApplicationCore
1>drwxr-xr-x 8 root root 4096 May 19 20:48 Infrastructure
1>drwxr-xr-x 13 root root 4096 May 19 22:18 Web
1>drwxr-xr-x 13 root root 4096 May 21 14:37 WebRazorPages
1>Removing intermediate container ecb2727f2649
1> ---> 01618f215b1a
1>Step 8/17 : WORKDIR /src/WebRazorPages
1>Removing intermediate container 7d812e8c1852
1> ---> b0c821c0cd10
1>Step 9/17 : RUN ls -la
1> ---> Running in 7055f247949a
1>total 100
1>drwxr-xr-x 13 root root 4096 May 21 14:37 .
1>drwxr-xr-x 1 root root 4096 May 21 14:37 ..
1>-rwxr-xr-x 1 root root 36 Oct 24 2017 .bowerrc
1>-rwxr-xr-x 1 root root 261 Apr 3 14:35 Constants.cs
1>drwxr-xr-x 2 root root 4096 Oct 24 2017 Controllers
1>-rwxr-xr-x 1 root root 475 May 21 14:37 Dockerfile
1>drwxr-xr-x 2 root root 4096 Oct 24 2017 Extensions
1>drwxr-xr-x 2 root root 4096 Oct 24 2017 Interfaces
1>drwxr-xr-x 6 root root 4096 May 19 21:36 Pages
1>-rwxr-xr-x 1 root root 1644 May 21 14:35 Program.cs
1>drwxr-xr-x 2 root root 4096 May 19 22:18 Properties
1>drwxr-xr-x 2 root root 4096 Oct 24 2017 Services
1>-rwxr-xr-x 1 root root 6297 May 19 21:11 Startup.cs
1>drwxr-xr-x 2 root root 4096 Apr 3 14:35 ViewComponents
1>drwxr-xr-x 2 root root 4096 Oct 24 2017 ViewModels
1>-rwxr-xr-x 1 root root 915 May 21 13:45 WebRazorPages.csproj
1>-rwxr-xr-x 1 root root 388 May 21 13:45 WebRazorPages.csproj.user
1>-rwxr-xr-x 1 root root 178 Oct 24 2017 appsettings.Development.json
1>-rwxr-xr-x 1 root root 113 Oct 24 2017 appsettings.json
1>drwxr-xr-x 4 root root 4096 May 21 13:59 bin
1>-rwxr-xr-x 1 root root 207 Oct 24 2017 bower.json
1>-rwxr-xr-x 1 root root 628 Oct 24 2017 bundleconfig.json
1>drwxr-xr-x 5 root root 4096 May 21 13:59 obj
1>drwxr-xr-x 7 root root 4096 Oct 24 2017 wwwroot
1>Removing intermediate container 7055f247949a
1> ---> 74b0f03086c2
1>Step 10/17 : RUN dotnet restore -nowarn:msb3202,nu1503
1> ---> Running in 33852929709e
1> Restoring packages for /src/Infrastructure/Infrastructure.csproj...
1> Restoring packages for /src/ApplicationCore/ApplicationCore.csproj...
1> Installing Ardalis.GuardClauses 1.2.3.
1> Generating MSBuild file /src/ApplicationCore/obj/ApplicationCore.csproj.nuget.g.props.
1> Generating MSBuild file /src/ApplicationCore/obj/ApplicationCore.csproj.nuget.g.targets.
1> Restore completed in 1.01 sec for /src/ApplicationCore/ApplicationCore.csproj.
1> Restoring packages for /src/WebRazorPages/WebRazorPages.csproj...
1> Installing System.Security.Cryptography.Cng 4.4.0.
1> Installing System.Numerics.Vectors 4.4.0.
1> Installing System.Buffers 4.4.0.
1> Generating MSBuild file /src/Infrastructure/obj/Infrastructure.csproj.nuget.g.props.
1> Generating MSBuild file /src/Infrastructure/obj/Infrastructure.csproj.nuget.g.targets.
1> Restore completed in 2.85 sec for /src/Infrastructure/Infrastructure.csproj.
1> Installing System.Runtime.CompilerServices.Unsafe 4.5.0-preview1-26216-02.
1> Installing Microsoft.Extensions.Logging.Abstractions 2.1.0-preview1-final.
1> Installing Microsoft.Extensions.DependencyInjection.Abstractions 2.1.0-preview1-final.
1> Installing Microsoft.Extensions.Configuration.Abstractions 2.1.0-preview1-final.
1> Installing Microsoft.Extensions.Primitives 2.1.0-preview1-final.
1> Installing Microsoft.Extensions.Hosting.Abstractions 2.1.0-preview1-final.
1> Installing Microsoft.AspNetCore.Hosting.Server.Abstractions 2.1.0-preview1-final.
1> Installing Microsoft.Extensions.FileSystemGlobbing 2.1.0-preview1-final.
1> Installing Microsoft.Extensions.FileProviders.Abstractions 2.1.0-preview1-final.
1> Installing Microsoft.Net.Http.Headers 2.1.0-preview1-final.
1> Installing System.Buffers 4.5.0-preview1-26216-02.
1> Installing Microsoft.AspNetCore.Http.Features 2.1.0-preview1-final.
1> Installing System.Text.Encodings.Web 4.5.0-preview1-26216-02.
1> Installing Microsoft.AspNetCore.Hosting.Abstractions 2.1.0-preview1-final.
1> Installing Microsoft.Extensions.FileProviders.Physical 2.1.0-preview1-final.
1> Installing Microsoft.AspNetCore.Http.Extensions 2.1.0-preview1-final.
1> Installing Microsoft.VisualStudio.Azure.Containers.Tools.Targets 0.1.1646902.
1> Installing Microsoft.VisualStudio.Web.BrowserLink 2.1.0-preview1-final.
1> Installing Microsoft.AspNetCore.Http.Abstractions 2.1.0-preview1-final.
1> Generating MSBuild file /src/WebRazorPages/obj/WebRazorPages.csproj.nuget.g.props.
1> Generating MSBuild file /src/WebRazorPages/obj/WebRazorPages.csproj.nuget.g.targets.
1> Restore completed in 2.49 sec for /src/WebRazorPages/WebRazorPages.csproj.
1>Removing intermediate container 33852929709e
1> ---> 0e020cc66427
1>Step 11/17 : RUN dotnet build --no-restore -c Release -o /app
1> ---> Running in da8aed1609f1
1>Microsoft (R) Build Engine version 15.7.177.53362 for .NET Core
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> You are working with a preview version of the .NET Core SDK. You can define the SDK version via a global.json file in the current project. More at https://go.microsoft.com/fwlink/?linkid=869452
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: The "KillAppInsideContainer" task failed unexpectedly. [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: System.DllNotFoundException: Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libkernel32.dll: cannot open shared object file: No such file or directory [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Common.Prerequisites.DockerForWindowsRunningPrerequisite.WaitNamedPipe(String name, Int32 timeout) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Common.Prerequisites.DockerForWindowsRunningPrerequisite.EvaluateAsync(CancellationToken cancellationToken) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Common.Prerequisites.CompositePrerequisite.EvaluateAsync(CancellationToken cancellationToken) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Tasks.ContainerBuildTask.HandleExceptionAsync(Exception ex, ContainerBuildTaskContext context) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Tasks.ContainerBuildTask.ExecuteAsync(ContainerBuildTaskContext context) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Tasks.ContainerBuildTask.Execute() [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/src/WebRazorPages/WebRazorPages.csproj]
1>Build FAILED.
1>
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: The "KillAppInsideContainer" task failed unexpectedly. [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: System.DllNotFoundException: Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libkernel32.dll: cannot open shared object file: No such file or directory [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Common.Prerequisites.DockerForWindowsRunningPrerequisite.WaitNamedPipe(String name, Int32 timeout) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Common.Prerequisites.DockerForWindowsRunningPrerequisite.EvaluateAsync(CancellationToken cancellationToken) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Common.Prerequisites.CompositePrerequisite.EvaluateAsync(CancellationToken cancellationToken) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Tasks.ContainerBuildTask.HandleExceptionAsync(Exception ex, ContainerBuildTaskContext context) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Tasks.ContainerBuildTask.ExecuteAsync(ContainerBuildTaskContext context) [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.VisualStudio.Containers.Tools.Tasks.ContainerBuildTask.Execute() [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/src/WebRazorPages/WebRazorPages.csproj]
1>/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/0.1.1646902/build/Container.targets(188,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/src/WebRazorPages/WebRazorPages.csproj]
1> 0 Warning(s)
1> 1 Error(s)
1>
1>Time Elapsed 00:00:00.66
1>The command '/bin/sh -c dotnet build --no-restore -c Release -o /app' returned a non-zero code: 1
1>C:\Users\steve\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\0.1.1646902\build\Container.targets(212,5): error : An error occurred while attempting to build Docker image.
1>Done building project "WebRazorPages.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========

为什么在文件夹中清楚地存在文件并且刚刚成功用于执行 dotnet restore时找不到该文件?

更新
该错误建议设置 LD_DEBUG,所以我这样做了,它产生了以下信息:
        21:     calling init: /lib/x86_64-linux-gnu/libnss_dns.so.2
21:
21: find library=kernel32.dll.so [0]; searching
21: search cache=/etc/ld.so.cache
21: search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib (system search path)
21: trying file=/lib/x86_64-linux-gnu/kernel32.dll.so
21: trying file=/usr/lib/x86_64-linux-gnu/kernel32.dll.so
21: trying file=/lib/kernel32.dll.so
21: trying file=/usr/lib/kernel32.dll.so
21:
21: find library=libkernel32.dll.so [0]; searching
21: search cache=/etc/ld.so.cache
21: search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib (system search path)
21: trying file=/lib/x86_64-linux-gnu/libkernel32.dll.so
21: trying file=/usr/lib/x86_64-linux-gnu/libkernel32.dll.so
21: trying file=/lib/libkernel32.dll.so
21: trying file=/usr/lib/libkernel32.dll.so
21:
21: find library=kernel32.dll [0]; searching
21: search cache=/etc/ld.so.cache
21: search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib (system search path)
21: trying file=/lib/x86_64-linux-gnu/kernel32.dll
21: trying file=/usr/lib/x86_64-linux-gnu/kernel32.dll
21: trying file=/lib/kernel32.dll
21: trying file=/usr/lib/kernel32.dll
21:
21: find library=libkernel32.dll [0]; searching
21: search cache=/etc/ld.so.cache
21: search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib (system search path)
21: trying file=/lib/x86_64-linux-gnu/libkernel32.dll
21: trying file=/usr/lib/x86_64-linux-gnu/libkernel32.dll
21: trying file=/lib/libkernel32.dll
21: trying file=/usr/lib/libkernel32.dll
21:
21: find library=Microsoft.DiaSymReader.Native.amd64.dll [0]; searching
21: search cache=/etc/ld.so.cache
21: search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib (system search path)
21: trying file=/lib/x86_64-linux-gnu/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/usr/lib/x86_64-linux-gnu/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/lib/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/usr/lib/Microsoft.DiaSymReader.Native.amd64.dll
21:
21: find library=Microsoft.DiaSymReader.Native.amd64.dll [0]; searching
21: search cache=/etc/ld.so.cache
21: search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib (system search path)
21: trying file=/lib/x86_64-linux-gnu/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/usr/lib/x86_64-linux-gnu/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/lib/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/usr/lib/Microsoft.DiaSymReader.Native.amd64.dll
21:
21: find library=Microsoft.DiaSymReader.Native.amd64.dll [0]; searching
21: search cache=/etc/ld.so.cache
21: search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib (system search path)
21: trying file=/lib/x86_64-linux-gnu/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/usr/lib/x86_64-linux-gnu/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/lib/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/usr/lib/Microsoft.DiaSymReader.Native.amd64.dll
21:
21: find library=Microsoft.DiaSymReader.Native.amd64.dll [0]; searching
21: search cache=/etc/ld.so.cache
21: search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib (system search path)
21: trying file=/lib/x86_64-linux-gnu/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/usr/lib/x86_64-linux-gnu/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/lib/Microsoft.DiaSymReader.Native.amd64.dll
21: trying file=/usr/lib/Microsoft.DiaSymReader.Native.amd64.dll
21:

最佳答案

当我使用 Visual Studio 2017(预览版)添加 > Docker 支持时,它为 microsoft.visualstudio.azure.containers.tools 添加了对 Web 项目的包引用.删除此引用使我克服了错误,我最终能够在那时对应用程序进行 dockerize。由于 VS 行为的在线文档仅说明它添加了一个 Dockerfile,而不是它与项目的其他困惑,因此添加此包并不是很明显。

关于docker - 使用 dotnet :2. 1-sdk 在 docker 容器中构建 dotnet 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50451348/

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