我有一个从使用 Paket 的 F# 项目构建的 docker 映像。在运行时,映像失败,并显示:
无法找到任何兼容的框架版本 指定的框架"Microsoft.AspNetCore.App",版本"2.2.7"为 未找到。
我的dockerfile
如下所示:
# Two stage build because Paket means project files reference external files
# via <Import Project="...paketPaket.Restore.targets" />
# https://github.com/fsprojects/Paket/issues/3006#issuecomment-359750323
FROM microsoft/dotnet:2.2-sdk-alpine AS build
RUN apk update
&& apk add --no-cache bash
WORKDIR /app
# copy fsproj and restore as distinct layers
COPY MyCompany.WebApi/MyCompany.WebApi.fsproj ./MyCompany.WebApi/
COPY NuGet.config ./
RUN dotnet restore MyCompany.WebApi/MyCompany.WebApi.fsproj --configfile NuGet.config
# copy everything else and build
COPY . ./
RUN dotnet publish MyCompany.WebApi/MyCompany.WebApi.fsproj -c Release -o out
# build runtime image
FROM microsoft/dotnet:2.2-sdk-alpine AS final
RUN apk update
&& apk add --no-cache bash
WORKDIR /app
COPY --from=build /app/MyCompany.WebApi/out ./
ENTRYPOINT ["dotnet", "MyCompany.WebApi.dll"]
如果我使用2.2-runtime-alpine
作为final
的基础,也会出现同样的问题。
我的packet.lock
包括以下行:
// https://github.com/fsharp/FAKE/issues/2193:
version 5.216.0
...
source https://api.nuget.org/v3/index.json
...
nuget Microsoft.AspNetCore.App
...
我注意到我生成的paket.dependencies
指定了Microsoft.AspNetCore.App
的特定版本:
Microsoft.AspNetCore.App (2.2.7)
Microsoft.AspNet.WebApi.Client (>= 5.2.6 < 5.3) - restriction: >= netcoreapp2.2
Microsoft.AspNetCore (>= 2.2 < 2.3) - restriction: >= netcoreapp2.2
Microsoft.AspNetCore.Antiforgery (>= 2.2 < 2.3) - restriction: >= netcoreapp2.2
。尽管看起来我们不鼓励指定版本:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-2.2
所以我的问题是:是否有可能提出Docker,Paket,F#和AspNetCore的组合来协同工作?
编辑:paket.dependencies
->packet.lock
编辑 2:以下是入口点目录的列表,如下所示:
.:
total 18668
-rwxr--r-- 1 root root 190976 Aug 29 13:18 Dapper.dll
-rwxr--r-- 1 root root 2850168 Aug 2 19:03 FSharp.Core.dll
-rwxr--r-- 1 root root 243200 Apr 16 08:00 Fable.Core.dll
-rwxr--r-- 1 root root 342528 Feb 10 2019 Giraffe.dll
...lots more DLLs from Nuget dependencies
... some DLLs from our internal dependencies
-rw-r--r-- 1 root root 100670 Sep 12 13:23 MyCompany.WebApi.deps.json
-rwxr-xr-x 1 root root 61440 Sep 12 13:23 MyCompany.WebApi.dll
-rw-r--r-- 1 root root 10608 Sep 12 13:23 MyCompany.WebApi.pdb
-rw-r--r-- 1 root root 149 Sep 12 13:23 MyCompany.WebApi.runtimeconfig.json
-rwxr--r-- 1 root root 178824 Nov 28 2018 System.Net.Http.Formatting.dll
-rwxr--r-- 1 root root 23088 Sep 18 2018 System.Runtime.CompilerServices.Unsafe.dll
-rwxr--r-- 1 root root 29744 Feb 15 2019 System.Security.Cryptography.OpenSsl.dll
-rwxr--r-- 1 root root 189168 Nov 29 2018 System.Security.Cryptography.Pkcs.dll
-rwxr--r-- 1 root root 29760 Jul 19 2018 System.ServiceModel.Primitives.dll
-rwxr--r-- 1 root root 30784 Jul 19 2018 System.ServiceModel.dll
-rwxr--r-- 1 root root 759024 Nov 29 2018 System.Text.Encoding.CodePages.dll
-rwxr--r-- 1 root root 91136 Sep 16 2018 TaskBuilder.fs.dll
drwxr-xr-x 2 root root 4096 Sep 12 13:23 cs
drwxr-xr-x 2 root root 4096 Sep 12 13:23 de
drwxr-xr-x 2 root root 4096 Sep 12 13:23 es
drwxr-xr-x 2 root root 4096 Sep 12 13:23 fr
drwxr-xr-x 2 root root 4096 Sep 12 13:23 it
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ja
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ko
drwxr-xr-x 2 root root 4096 Sep 12 13:23 pl
-rwxr--r-- 1 root root 277504 Aug 30 2018 protobuf-net.dll
drwxr-xr-x 2 root root 4096 Sep 12 13:23 pt-BR
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ru
drwxr-xr-x 4 root root 4096 Sep 12 13:23 runtimes
drwxr-xr-x 2 root root 4096 Sep 12 13:23 tr
drwxr-xr-x 2 root root 4096 Sep 12 13:23 zh-Hans
drwxr-xr-x 2 root root 4096 Sep 12 13:23 zh-Hant
./cs:
total 376
-rwxr--r-- 1 root root 33144 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 308088 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 34896 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./de:
total 392
-rwxr--r-- 1 root root 34168 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 327544 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./es:
total 388
-rwxr--r-- 1 root root 33360 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 321104 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35920 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./fr:
total 392
-rwxr--r-- 1 root root 33656 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 327544 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36432 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./it:
total 392
-rwxr--r-- 1 root root 33144 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 325496 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./ja:
total 428
-rwxr--r-- 1 root root 35704 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 358776 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 38264 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./ko:
total 396
-rwxr--r-- 1 root root 34680 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 331336 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36728 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./pl:
total 396
-rwxr--r-- 1 root root 34168 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 331128 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./pt-BR:
total 380
-rwxr--r-- 1 root root 32632 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 316280 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35704 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./ru:
total 508
-rwxr--r-- 1 root root 39800 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 430968 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 42360 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./runtimes:
total 8
drwxr-xr-x 3 root root 4096 Sep 12 13:23 unix
drwxr-xr-x 3 root root 4096 Sep 12 13:23 win
./runtimes/unix:
total 4
drwxr-xr-x 4 root root 4096 Sep 12 13:23 lib
./runtimes/unix/lib:
total 8
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.1
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netstandard2.0
./runtimes/unix/lib/netcoreapp2.1:
total 88
-rwxr--r-- 1 root root 86280 Feb 15 2019 System.Security.Cryptography.OpenSsl.dll
./runtimes/unix/lib/netstandard2.0:
total 1848
-rwxr--r-- 1 root root 1889344 Jul 19 2018 System.Private.ServiceModel.dll
./runtimes/win:
total 4
drwxr-xr-x 5 root root 4096 Sep 12 13:23 lib
./runtimes/win/lib:
total 12
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.0
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.1
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netstandard2.0
./runtimes/win/lib/netcoreapp2.0:
total 744
-rwxr--r-- 1 root root 761392 Nov 29 2018 System.Text.Encoding.CodePages.dll
./runtimes/win/lib/netcoreapp2.1:
total 212
-rwxr--r-- 1 root root 214064 Nov 29 2018 System.Security.Cryptography.Pkcs.dll
./runtimes/win/lib/netstandard2.0:
total 1848
-rwxr--r-- 1 root root 1889344 Jul 19 2018 System.Private.ServiceModel.dll
./tr:
total 376
-rwxr--r-- 1 root root 32632 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 312184 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35192 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./zh-Hans:
total 344
-rwxr--r-- 1 root root 31096 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 278904 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 33144 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./zh-Hant:
total 344
-rwxr--r-- 1 root root 30584 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 280144 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 33360 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
我想我已经解决了这个问题。将基本映像更改为我在Microsoft教程中找到的引用映像,并删除了apk update
阶段(因为这返回了此新基本映像的非零退出代码(。这就是我现在dockerfile
。
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app
# copy fsproj and restore as distinct layers
COPY MyCompany.WebApi/MyCompany.WebApi.fsproj ./MyCompany.WebApi/
COPY NuGet.config ./
RUN dotnet restore MyCompany.WebApi/MyCompany.WebApi.fsproj --configfile NuGet.config
# copy everything else and build
COPY . ./
RUN dotnet publish MyCompany.WebApi/MyCompany.WebApi.fsproj -c Release -o out
# build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS final
WORKDIR /app
COPY --from=build /app/MyCompany.WebApi/out ./
ENTRYPOINT ["dotnet", "MyCompany.WebApi.dll"]
它现在启动正常,尚未测试该功能!
我远不是Docker或Linux专家,但我冒昧地猜测Alpine图像没有赶上最新的dotnet版本。我也猜想我在这次更改后创建的图像比它需要的更胖,但我现在会采用"脂肪和工作"。