我正在尝试构建一个简单的dotnet core
应用程序并将其包装在docker映像中。在映像构建期间,所有dotnet
命令(如dotnet restore
或dotnet build
)将永远运行而不会取得任何进展,但占用CPU约50%。我让它运行了至少一个小时,但它从未停止过。普通的dotnet restore
只需花费几毫秒的时间,因此肯定会有一些问题。
复制步骤。
dotnet --version
mkdir TestApplication
cd TestApplication
dotnet new console
dotnet run/restore/build
一切正常FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /
COPY *.csproj ./
RUN dotnet restore
COPY . .
RUN dotnet build
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
COPY --from=build /aspnetapp/out ./
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
docker build -t myTestApplication .
结果:始终在第一个dotnet
命令处挂起,即使正在播放也是如此。在macOS Catalina(10.15.6)上运行。
任何人都知道这里出了什么问题吗?我尝试为效果良好的Python应用程序创建图像,因此它似乎与dotnet
有关。
修改1: 添加详细的日志输出:
(base) ➜ TestApplication docker build -t testerico .
Sending build context to Docker daemon 5.12kB
Step 1/9 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
---> 9ab567a29502
Step 2/9 : WORKDIR /
---> Using cache
---> ec8404eb93c3
Step 3/9 : COPY *.csproj ./
---> Using cache
---> 86a4e6875b03
Step 4/9 : RUN dotnet restore --verbosity diagnostic
---> Running in 1791f6205c36
/usr/share/dotnet/sdk/3.1.401/MSBuild.dll -nologo -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/share/dotnet/sdk/3.1.401/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,/usr/share/dotnet/sdk/3.1.401/dotnet.dll -maxcpucount -target:Restore -verbosity:m -verbosity:diagnostic ./TestApplication.csproj
Build started 08/29/2020 11:49:23.
Environment at start of build:
NUGET_XMLDOC_MODE = skip
DOTNET_USE_POLLING_FILE_WATCHER = true
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DOTNET_RUNNING_IN_CONTAINER = true
HOME = /root
DOTNET_HOST_PATH = /usr/share/dotnet/dotnet
POWERSHELL_DISTRIBUTION_CHANNEL = PSDocker-DotnetCoreSDK-Debian-10
MSBuildExtensionsPath = /usr/share/dotnet/sdk/3.1.401/
MSBuildSDKsPath = /usr/share/dotnet/sdk/3.1.401/Sdks
HOSTNAME = 1791f6205c36
PWD = /
DOTNET_CLI_TELEMETRY_SESSIONID = af7fc2b0-1308-4572-99e7-30bae6e369e8
MSBuildLoadMicrosoftTargetsReadOnly = true
11:49:23.778 0>Process = "/usr/share/dotnet/dotnet"
MSBuild executable path = "/usr/share/dotnet/sdk/3.1.401/MSBuild.dll"
Command line arguments = "/usr/share/dotnet/sdk/3.1.401/MSBuild.dll -maxcpucount -verbosity:m -nologo -target:Restore -verbosity:diagnostic -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/share/dotnet/sdk/3.1.401/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,/usr/share/dotnet/sdk/3.1.401/dotnet.dll"
Current directory = "/"
MSBuild version = "16.7.0-preview-20360-03+188921e2f"
Resolving SDK 'Microsoft.NET.Sdk'...
Property reassignment: $(MSBuildProjectExtensionsPath)="/obj/" (previous value: "obj\") at /usr/share/dotnet/sdk/3.1.401/Current/Microsoft.Common.props (56,5)
Property reassignment: $(TargetsForTfmSpecificContentInPackage)=";PackTool;_PackProjectToolValidation" (previous value: ";PackTool") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.PackProjectTool.props (15,5)
Property reassignment: $(OutputType)="Exe" (previous value: "Library") at /TestApplication.csproj (4,5)
Property reassignment: $(PublishProfileImported)="false" (previous value: "true") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportPublishProfile.targets (28,5)
Property reassignment: $(DefaultItemExcludes)=";bin/Debug//**;obj\Debug\/**" (previous value: ";bin/Debug//**") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets (171,5)
Property reassignment: $(IntermediateOutputPath)="obj\Debug\netcoreapp3.1\" (previous value: "obj\Debug\") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets (185,5)
Property reassignment: $(OutputPath)="bin/Debug/netcoreapp3.1/" (previous value: "bin/Debug/") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets (186,5)
Property reassignment: $(_FrameworkVersionForImplicitDefine)="3_1" (previous value: "3.1") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.BeforeCommon.targets (165,5)
Property reassignment: $(_DebugSymbolsProduced)="true" (previous value: "false") at /usr/share/dotnet/sdk/3.1.401/Microsoft.Common.CurrentVersion.targets (149,5)
Property reassignment: $(_DocumentationFileProduced)="false" (previous value: "true") at /usr/share/dotnet/sdk/3.1.401/Microsoft.Common.CurrentVersion.targets (158,5)
Property reassignment: $(ProcessorArchitecture)="msil" (previous value: "") at /usr/share/dotnet/sdk/3.1.401/Microsoft.Common.CurrentVersion.targets (487,5)
Property reassignment: $(DelaySign)="" (previous value: "false") at /usr/share/dotnet/sdk/3.1.401/Microsoft.Common.CurrentVersion.targets (527,5)
Property reassignment: $(_SGenGenerateSerializationAssembliesConfig)="Auto" (previous value: "") at /usr/share/dotnet/sdk/3.1.401/Microsoft.Common.CurrentVersion.targets (3491,5)
Property reassignment: $(_SGenGenerateSerializationAssembliesConfig)="Off" (previous value: "Auto") at /usr/share/dotnet/sdk/3.1.401/Microsoft.Common.CurrentVersion.targets (3492,5)
Property reassignment: $(MSBuildAllProjects)=";/usr/share/dotnet/sdk/3.1.401/NuGet.targets;/usr/share/dotnet/sdk/3.1.401/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets" (previous value: ";/usr/share/dotnet/sdk/3.1.401/NuGet.targets") at /usr/share/dotnet/sdk/3.1.401/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets (16,5)
Property reassignment: $(ProjectAssetsFile)="/obj/project.assets.json" (previous value: "/obj//project.assets.json") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets (24,5)
Property reassignment: $(ProjectAssetsCacheFile)="/obj/Debug/netcoreapp3.1/TestApplication.assets.cache" (previous value: "obj\Debug\netcoreapp3.1\TestApplication.assets.cache") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets (29,5)
Property reassignment: $(ResolveAssemblyReferencesDependsOn)="
ResolveProjectReferences;
FindInvalidProjectReferences;
GetFrameworkPaths;
GetReferenceAssemblyPaths;
PrepareForBuild;
ResolveSDKReferences;
ExpandSDKReferences;
;
ResolvePackageDependenciesForBuild;
_HandlePackageFileConflicts;
" (previous value: "
ResolveProjectReferences;
FindInvalidProjectReferences;
GetFrameworkPaths;
GetReferenceAssemblyPaths;
PrepareForBuild;
ResolveSDKReferences;
ExpandSDKReferences;
") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets (71,5)
Property reassignment: $(PrepareResourcesDependsOn)="
ResolvePackageDependenciesForBuild;
_HandlePackageFileConflicts;
;
PrepareResourceNames;
ResGen;
CompileLicxFiles
" (previous value: "
;
PrepareResourceNames;
ResGen;
CompileLicxFiles
") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets (77,5)
Property reassignment: $(DefaultItemExcludes)=";bin/Debug//**;obj\Debug\/**;bin//**" (previous value: ";bin/Debug//**;obj\Debug\/**") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets (27,5)
Property reassignment: $(DefaultItemExcludes)=";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**" (previous value: ";bin/Debug//**;obj\Debug\/**;bin//**") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets (29,5)
Property reassignment: $(DefaultItemExcludes)=";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**;**/*.user" (previous value: ";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets (32,5)
Property reassignment: $(DefaultItemExcludes)=";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**;**/*.user;**/*.*proj" (previous value: ";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**;**/*.user") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets (33,5)
Property reassignment: $(DefaultItemExcludes)=";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**;**/*.user;**/*.*proj;**/*.sln" (previous value: ";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**;**/*.user;**/*.*proj") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets (34,5)
Property reassignment: $(DefaultItemExcludes)=";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**;**/*.user;**/*.*proj;**/*.sln;**/*.vssscc" (previous value: ";bin/Debug//**;obj\Debug\/**;bin//**;obj\/**;**/*.user;**/*.*proj;**/*.sln") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets (35,5)
Property reassignment: $(ResolveAssemblyReferencesDependsOn)="
ResolveProjectReferences;
FindInvalidProjectReferences;
GetFrameworkPaths;
GetReferenceAssemblyPaths;
PrepareForBuild;
ResolveSDKReferences;
ExpandSDKReferences;
;
ResolvePackageDependenciesForBuild;
_HandlePackageFileConflicts;
;
ResolveTargetingPackAssets;
" (previous value: "
ResolveProjectReferences;
FindInvalidProjectReferences;
GetFrameworkPaths;
GetReferenceAssemblyPaths;
PrepareForBuild;
ResolveSDKReferences;
ExpandSDKReferences;
;
ResolvePackageDependenciesForBuild;
_HandlePackageFileConflicts;
") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets (14,5)
Property reassignment: $(_GenerateRuntimeConfigurationPropertyInputsCache)="/obj/Debug/netcoreapp3.1/TestApplication.genruntimeconfig.cache" (previous value: "obj\Debug\netcoreapp3.1\TestApplication.genruntimeconfig.cache") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets (53,5)
Property reassignment: $(_DefaultUserProfileRuntimeStorePath)="/root/.dotnet/store" (previous value: "/root") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets (97,5)
Property reassignment: $(CoreBuildDependsOn)="
_CheckForBuildWithNoBuild;
BuildOnlySettings;
PrepareForBuild;
PreBuildEvent;
ResolveReferences;
PrepareResources;
ResolveKeySource;
Compile;
ExportWindowsMDFile;
UnmanagedUnregistration;
GenerateSerializationAssemblies;
CreateSatelliteAssemblies;
GenerateManifests;
GetTargetPath;
PrepareForRun;
UnmanagedRegistration;
IncrementalClean;
PostBuildEvent
;
GenerateBuildDependencyFile;
GenerateBuildRuntimeConfigurationFiles
" (previous value: "
BuildOnlySettings;
PrepareForBuild;
PreBuildEvent;
ResolveReferences;
PrepareResources;
ResolveKeySource;
Compile;
ExportWindowsMDFile;
UnmanagedUnregistration;
GenerateSerializationAssemblies;
CreateSatelliteAssemblies;
GenerateManifests;
GetTargetPath;
PrepareForRun;
UnmanagedRegistration;
IncrementalClean;
PostBuildEvent
") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets (118,5)
Property reassignment: $(CoreCleanDependsOn)="
_SdkBeforeClean;
" (previous value: "") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets (127,5)
Property reassignment: $(RebuildDependsOn)="
_SdkBeforeRebuild;
BeforeRebuild;
Clean;
Build;
AfterRebuild;
" (previous value: "
BeforeRebuild;
Clean;
Build;
AfterRebuild;
") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets (134,5)
Property reassignment: $(CompileDependsOn)="
ResolveReferences;
ResolveKeySource;
SetWin32ManifestProperties;
FindReferenceAssembliesForReferences;
_GenerateCompileInputs;
BeforeCompile;
_TimeStampBeforeCompile;
_GenerateCompileDependencyCache;
CoreCompile;
_TimeStampAfterCompile;
AfterCompile;
;
_CreateAppHost;
_CreateComHost;
_GetIjwHostPaths;
" (previous value: "
ResolveReferences;
ResolveKeySource;
SetWin32ManifestProperties;
FindReferenceAssembliesForReferences;
_GenerateCompileInputs;
BeforeCompile;
_TimeStampBeforeCompile;
_GenerateCompileDependencyCache;
CoreCompile;
_TimeStampAfterCompile;
AfterCompile;
") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets (396,5)
Property reassignment: $(CreateSatelliteAssembliesDependsOn)="
_GenerateSatelliteAssemblyInputs;
ComputeIntermediateSatelliteAssemblies;
GenerateSatelliteAssemblies
;
CoreGenerateSatelliteAssemblies
" (previous value: "
_GenerateSatelliteAssemblyInputs;
ComputeIntermediateSatelliteAssemblies;
GenerateSatelliteAssemblies
") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets (758,5)
Property reassignment: $(DesignerRuntimeImplementationProjectOutputGroupDependsOn)="
;
;
BuildOnlySettings;
PrepareForBuild;
AssignTargetPaths;
ResolveReferences
;
_GenerateDesignerDepsFile;
_GenerateDesignerRuntimeConfigFile;
_GatherDesignerShadowCopyFiles;
" (previous value: "
;
;
BuildOnlySettings;
PrepareForBuild;
AssignTargetPaths;
ResolveReferences
") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.DesignerSupport.targets (21,5)
Property reassignment: $(_ShimInputCacheFile)="/obj/Debug/netcoreapp3.1/TestApplication.shiminput.cache" (previous value: "obj\Debug\netcoreapp3.1\TestApplication.shiminput.cache") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.PackTool.targets (94,5)
Property reassignment: $(_ShimCreatedSentinelFile)="/obj/Debug/netcoreapp3.1/TestApplication.shimcreated.sentinel" (previous value: "obj\Debug\netcoreapp3.1\TestApplication.shimcreated.sentinel") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.PackTool.targets (96,5)
Property reassignment: $(DefineConstants)="TRACE;DEBUG" (previous value: "TRACE") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.CSharp.targets (31,5)
Property reassignment: $(DefineConstants)="TRACE;DEBUG;NETCOREAPP;NETCOREAPP3_1" (previous value: "TRACE;DEBUG") at /usr/share/dotnet/sdk/3.1.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.CSharp.targets (34,5)
Resolving SDK 'ILLink.Tasks'...
Property reassignment: $(MSBuildAllProjects)=";/usr/share/dotnet/sdk/3.1.401/NuGet.targets;/usr/share/dotnet/sdk/3.1.401/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets;/usr/share/dotnet/sdk/3.1.401/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets" (previous value: ";/usr/share/dotnet/sdk/3.1.401/NuGet.targets;/usr/share/dotnet/sdk/3.1.401/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets") at /usr/share/dotnet/sdk/3.1.401/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets (18,5)
Property reassignment: $(PackageDescription)="Package Description" (previous value: "") at /usr/share/dotnet/sdk/3.1.401/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets (32,5)
Property reassignment: $(GenerateNuspecDependsOn)="Build;_LoadPackInputItems; _GetTargetFrameworksOutput; _WalkEachTargetPerFramework; _GetPackageFiles; " (previous value: "_LoadPackInputItems; _GetTargetFrameworksOutput; _WalkEachTargetPerFramework; _GetPackageFiles; ") at /usr/share/dotnet/sdk/3.1.401/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets (55,5)
答案 0 :(得分:1)
“我认为该问题缺少WORKDIR /app
指令,我添加了它,现在它可以正常工作了。太奇怪了……”
https://github.com/dotnet/core/issues/1825
因此,将WORKDIR /
更改为WORKDIR /app
应该可以解决问题。
Doc for Core 3.1中的Docker文件:https://docs.docker.com/engine/examples/dotnetcore/
由VS生成的典型Docker文件如下所示,并使用Core Debian映像(在部署到OpenShift / Kubernetes时,我也在使用该映像)。在下面的示例中,我的应用程序名为“ WebApplication”。
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication.csproj", ""]
RUN dotnet restore "./WebApplication.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication.dll"]