Home > Back-end >  A compatible installed .NET Core SDK for global.json version [6.0.402] from [/app/global.json] was n
A compatible installed .NET Core SDK for global.json version [6.0.402] from [/app/global.json] was n

Time:10-13

So I generated a project with dotnet new webapi and I added a Dockerfile,when I try to run docker build -t pregrad/weatherapi . I get the following message:

[ ] Building 1.1s (13/14)
 => [internal] load build definition from Dockerfile                                                                                                                                                                0.0s 
 => => transferring dockerfile: 32B                                                                                                                                                                                 0.0s 
 => [internal] load .dockerignore                                                                                                                                                                                   0.0s 
 => => transferring context: 2B                                                                                                                                                                                     0.0s 
 => [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:3.1                                                                                                                                           0.4s 
 => [internal] load metadata for mcr.microsoft.com/dotnet/core/sdk:3.1                                                                                                                                              0.4s 
 => [stage-1 1/3] FROM mcr.microsoft.com/dotnet/core/aspnet:3.1@sha256:1830f7a5dbe41cc341235072f9b1c2de7163a4c89b505a4a31a5fbe3b281539e                                                                             0.0s 
 => [build-env 1/6] FROM mcr.microsoft.com/dotnet/core/sdk:3.1@sha256:53a7a7d70ac0473e9e06ccd8a4992160b58952c3dbdd91ef3e6c28dc5760ed6f                                                                              0.0s 
 => [internal] load build context                                                                                                                                                                                   0.0s 
 => => transferring context: 1.61kB                                                                                                                                                                                 0.0s 
 => CACHED [stage-1 2/3] WORKDIR /app                                                                                                                                                                               0.0s 
 => CACHED [build-env 2/6] WORKDIR /app                                                                                                                                                                             0.0s 
 => CACHED [build-env 3/6] COPY *.csproj ./                                                                                                                                                                         0.0s 
 => CACHED [build-env 4/6] RUN dotnet restore                                                                                                                                                                       0.0s 
 => [build-env 5/6] COPY . ./                                                                                                                                                                                       0.1s 
 => ERROR [build-env 6/6] RUN dotnet publish -c Release -o out                                                                                                                                                      0.4s 
------
 > [build-env 6/6] RUN dotnet publish -c Release -o out:
#13 0.381 A compatible installed .NET Core SDK for global.json version [6.0.402] from [/app/global.json] was not found
#13 0.381 Install the [6.0.402] .NET Core SDK or update [/app/global.json] with an installed .NET Core SDK:
#13 0.381   3.1.424 [/usr/share/dotnet/sdk]
------
executor failed running [/bin/sh -c dotnet publish -c Release -o out]: exit code: 145

When I run dotnet --list-sdks I get the following:

3.1.424 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
6.0.402 [C:\Program Files\dotnet\sdk]

CodePudding user response:

The nice thing about Docker is that it's very self-contained and isolated from the host machine. So it doesn't matter what SDKs are installed on the host machine. There doesn't even need to be a single .NET SDK installed on the host machine. It only matters what SDK you use in your Dockerfile.

The logs show that you're using the 3.1 SDK in the line

FROM mcr.microsoft.com/dotnet/core/sdk:3.1

You need to edit your Dockerfile, so it uses the 6.0 SDK by changing the line to (note that there's no longer core in the name)

FROM mcr.microsoft.com/dotnet/sdk:6.0

Further down in the Dockerfile you'll see that it uses the 3.1 aspnet image as the runtime image. The line is

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1

You must change that to

FROM mcr.microsoft.com/dotnet/aspnet:6.0

so it matches the SDK version.

  • Related