2
votes

I have a docker image built from an F# project that uses Paket. At run time the image fails with:

It was not possible to find any compatible framework version The specified framework 'Microsoft.AspNetCore.App', version '2.2.7' was not found.

My dockerfile looks like this:

# Two stage build because Paket means project files reference external files
# via <Import Project="..\.paket\Paket.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"]

Same problem occurs if I use 2.2-runtime-alpine as the basis for final.

My packet.lock includes these lines:

// https://github.com/fsharp/FAKE/issues/2193:
version 5.216.0
...
source https://api.nuget.org/v3/index.json
...
nuget Microsoft.AspNetCore.App
...

I notice that my generated paket.dependencies specifies a particular version of 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

...although it looks like we are discouraged from specifying versions:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-2.2

So my question is: is it possible to come up with a combination of Docker, Paket, F# and AspNetCore that works together?

Edit: paket.dependencies -> packet.lock

Edit 2: Here's a listing of the entry point's directory and below:

.:
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
1
What you call a "generated paket.dependencies file" is actaully a paket.lock file, which records the versions that Paket calculated and installed from your paket.dependencies. Your paket.dependencies file is not specifying a specific version of AspNetCore.App: the nuget Microsoft.AspNetCore.App line doesn't have any version appended to it. What you've shown us so far should work as far as I can see, though I'm not an expert on Docker. What does the Docker container look like at the time you run it? I.e., what files are beside MyCompany.WebApi.dll in the container image?rmunn
@rmunn You're right - fixed file name. Point taken about the versioning. I'll dig out a container content listing. Thanks!Kit

1 Answers

2
votes

I think I've fixed this. Changed the base image to one I found referenced in a Microsoft tutorial, and removed the apk update stage (as this returned a non-zero exit code with this new base image). So this is my dockerfile now.

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"]

It starts up OK now, haven't yet tested the functionality!

I am far from a Docker or Linux expert, but I would hazard a guess that the Alpine image hasn't caught up with the latest dotnet releases. I would also guess that the image I create after this change is fatter than it needs to be, but I'll take 'fat and working' for now.