Reputation: 14205
I have .net core app which is dockerized Inside docker compose file bellow there are details of this container docker-compose up from windows cli produces following error
Step 11/20 : RUN dotnet restore My.Api/My.Api.csproj
---> Running in bc9d0ee76a7e
/usr/share/dotnet/sdk/2.1.202/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.2. [/src/My.Api/My.Api.csproj]
ERROR: Service 'my.api' failed to build: The command '/bin/sh -c dotnet restore My.Api/My.Api.csproj' returned a non-zero code: 1
docker-compose.yml
version: '3.4'
networks:
frontend:
backend:
services:
my.api:
image: ${DOCKER_REGISTRY}myapi
build:
context: .
dockerfile: My.Api/Dockerfile
ports:
- "5000:80"
networks:
- backend
- frontend
depends_on:
- mssqlserver
mssqlserver:
image: "microsoft/mssql-server-linux:latest"
.....
Dockerfile
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY My.Api/
RUN dotnet restore My.Api.csproj
COPY . .
WORKDIR /src/My.Api
RUN dotnet build My.Api.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish My.Api.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "My.Api.dll"]
dotnet --version
2.2.105
Update:
When I change Dockerfile to use microsoft/aspnetcore:2.2 instead of microsoft/aspnetcore:2.0 I'm getting
Step 1/20 : FROM microsoft/aspnetcore:2.2 AS base
ERROR: Service 'my.api' failed to build: manifest for microsoft/aspnetcore:2.2 not found
Upvotes: 0
Views: 1202
Reputation: 15233
First, an important point:
The versions of .NET Core installed in Windows don't matter when it comes to a docker container. Whatever dotnet --version
says in Windows doesn't matter. A docker container is a separate environment from your Windows environment. It actually runs a different userspace (Linux, not Windows). It can have a completely different set of programs and versions installed.
Now, going back, the error says:
error : The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.2
The last part of this error message is really important. It tells you the problem: you are using a .NET Core SDK (inside the docker container) that can not target 2.2.
(Remember that the version of .NET Core SDK that's normally installed in Windows is irrelevant for docker?)
So that version of the SDK are you using inside the docker container? Look at the Dockerfile
again:
FROM microsoft/aspnetcore-build:2.0 AS build
You are using a .NET Core SDK that supports ASP.NET Core 2.0. In other words, you are using .NET Core SDK 2.0 and it only supports targetting .NET Core 2.0. You need to switch to an SDK that supports .NET Core 2.2.
Change FROM microsoft/aspnetcore:2.0 AS base
to FROM microsoft/aspnetcore:2.2 AS base
and FROM microsoft/aspnetcore-build:2.0 AS build
to FROM microsoft/aspnetcore-build:2.2 AS build
.
That will get you an SDK that lets you target .NET Core 2.2.
Edit: Ah, right. I missed something.
The Microsoft container images are described here. You need to use microsoft/dotnet:2.2-sdk
for building (FROM microsoft/dotnet:2.2-sdk AS build
) and microsoft/dotnet:2.2-aspnetcore-runtime
for running (FROM microsoft/dotnet:2.2-aspnetcore-runtime as base
).
Upvotes: 1