Docker did not find any installed .NET Core SDKs - docker

I have looked at other posts related to this and couldn't resolve the issue.
Docker File:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY webapp/*.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY ./webapp ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT [ "dotnet", "weppapp.dll" ]
Local version of .NET Core:
PS C:\Repository\AzureCLIScripts\AZ203\ContainerizedSolutions> dotnet --version
3.1.201
I'm following along a training course on Docker, primarily related to the AZ-203 course, so I'm sure the original code is for .NET Core 2.1. I've researched as best I can, but can't seem to get the app to run inside of docker, when it runs fine locally.
When I run the following I get the error below:
PS C:\Repository\AzureCLIScripts\AZ203\ContainerizedSolutions> docker run -p 8081:80 --name mywebapp webapp
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download
Any suggestions?

This happened to me when I changed the assembly name in the project but forgot to change it in the Dockerfile. Assembly name is in the project properties.

Related

.net web api with docker Could not execute because the application was not found or a compatible .NET SDK is not installed

I am trying to run a .net web api on docker but it won't work. I have already tried the link below and it won't work.
Could not execute because the application was not found or a compatible .NET SDK is not installed
I have also tried installing the .NET 5 SDK. Running the command 'dotnet' also works. Below is my docker file.
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["Catalog.csproj", "./"]
RUN dotnet restore "Catalog.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet publish "Catalog.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "Catalog.dll"]
And I am trying to run it using the following command.
docker run -it --rm -p 8080:80 -e MongoDbSettings:Host=mongo -e MongoDbSettings:Password=mypass --network=net5tutorial catalog:v1
This is my complete error message
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application 'Catalog.dll' does not exist.
* You intended to execute a .NET SDK command:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
I hope you can help me, I am on a Mac should this be of any importance. Thanks in advance

Issue with run docker image for Blazor WebAssembly App

Can anyone please help me to create a docker file for blazor webassembly ?
I am trying to creating docker file for blazor webassembly.
I have checked many docs and I have tried with many docker files. Every time my docker image build successful but when I run that image at that time I am getting error like below
"It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from: https://aka.ms/dotnet-download"
I am using below code
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "BlazorDemo.dll"]
This is my build command and it's working fine
docker build --tag blazordemo .
Below run command I have tried and here I am getting error
docker run --publish 8001:80 --detach --name blazortestapp blazordemo
docker run -p 8080:80 blazordemo
Note - Blazor WebAssembly target framework is .NET Standard 2.1

.NET Core 3.0 Web API won't start in Docker container

I'm fresh to Docker, trying to get a proof of concept container running on my machine. I generated a .NET Core 3.0 Web API project using the command dotnet new webapi. I've added a controller endpoint that simply returns a string "Hello World."
using System;
using Microsoft.AspNetCore.Mvc;
namespace DockerHelloWorld.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ValuesController : ControllerBase
{
[HttpGet]
public string Get()
{
return "Hello World!";
}
}
}
I am able to successfully build and run this project using dotnet build and dotnet run respectively.
I am now trying to get this to run in a Docker container. Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish --framework netcoreapp3 --configuration Release --output out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DockerHellWorld.dll"]
This is copied and slightly modified from here.
I also have the following .dockerignore, just in case it is relevant:
bin\
obj\
*.md
*.png
I run the following commands:
docker build -t dockerhelloworldimage .
docker create -p 3000:80 --name dockerhelloworldcontainer dockerhelloworldimage
docker start dockerhelloworldcontainer
It seems like each step is being ran based on the output of docker build. A hash is returned after docker create and "dockerhelloworldcontainer" is returned after docker run.
The container stops immediately. I see this by using the docker container ls -a command.
docker logs dockerhelloworldcontainer has the following output: "It was not possible to find any installed .NET Core SDKs. Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from: https://aka.ms/dotnet-download" but I don't really know how to make sense of that.
It's worth mentioning, I got something very similar to this working with a .NET Core 2.2 app.
Any ideas? What could I be missing?
The issue as #Zied mentioned in the comment, is a typo in the Assembly name you want to call from the entrypoint command.
If you fix that on the docker file:
# All other content remains the same
ENTRYPOINT ["dotnet", "DockerHelloWorld.dll"]
You'll get your container successfully started.
Listing running containers: docker ps shows:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7dcb5c122445 dockerhelloworldimage "dotnet DockerHelloW…" 5 minutes ago Up 4 minutes 0.0.0.0:3000->80/tcp dockerhelloworldcontainer
Now, this can look like a misleading error message, but if you try to actually run a wrong dotnet executable from the CLI (not from docker):
> dotnet MyNonExistingExeName.dll
You'll get the below message:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-.\bin\Debug\netcoreapp3.0\DockerHellWorld.dll does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
I believe that the second and third bullets apply to this case. What that means is that if you have a dotnet executable (or a global/local tool) you can run them with the dotnet command so the issue is that your command is being interpreted as a non-existent tool or command and hence the error.
Hope this helps!
Run the below command to deploy sample Dotnet web API code on docker
docker-compose build
docker-compose up
Dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
COPY ./SampleWebApi3.0.csproj /SampleWebApi3.0/
RUN dotnet restore ./SampleWebApi3.0/SampleWebApi3.0.csproj
COPY . ./SampleWebApi3.0/
WORKDIR /SampleWebApi3.0/
RUN dotnet build "SampleWebApi3.0.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SampleWebApi3.0.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SampleWebApi3.0.dll"]
docker-compose.yml
version: '3.5'
services:
sample-web-api:
build: SampleWebApi3.0/
restart: always
ports:
- "8085:80"
Sample web API code 3.0 along with Dockerfile on Github

Why is multi step docker build better?

I have been updating our dotnet core application from dotnet 2.0 to 2.1 and I see that multi step dockerfiles are now suggested. I read that it is more efficent to build your app inside a container with the dotnet SDK and then copy to a different container with just the runtime. https://github.com/dotnet/announcements/issues/18
I am wondering why this would be better that how we did it with our 2.0 images which would be to run dotnet publish MySolution.sln -c Release -o ./obj/Docker/publish on our build server (dotnet 2.1 sdk is installed on it) and then do a single step build where we copy the build output to an image.
It is claimed to be simpler to do a multi step build, but it seems more complicated to me to copy over everything you need for a build, and then copy the results to another container.
Here is what the multi step Dockerfile looks like
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY myproject.csproj app/
RUN dotnet restore myproject.csproj
COPY . .
WORKDIR /src/Setting
RUN dotnet restore myproject.csproj
RUN dotnet build myproject.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish myproject.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "myproject.dll"]
vs a single step one.
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "Myproject.dll"]
Any thoughts?
I read that it is more efficent to build your app inside a container with the dotnet SDK and then copy to a different container with just the runtime.
I believe that this description already exists before .Net Core 2.1 in the official documentation of Docker.
This is simply because you need SDK only to build your application, but if you have already built the application somewhere else, you can directly run it on runtime container (not SDK container). I did that a lot when no SDK were available for ARM processors, I had to build the application on my PC, then had to copy it to the target device. That was not that easy, because I always had dependencies problems, which I had to solve manually.
Therefore, it is almost always recommended to build the application on the machine you want to deploy the app on. This guaranties that your application will be build with the proper settings for that exact software and hardware requirements.
Because of that, I would always build the application on the target deploying device (on SDK container), and then copy the output of building to runtime container.
Now you are asking: why not simply run the application in SDK container? The only reason is probably because it will be significantly larger and heavier than any runtime container (as it has runtime environment + building tools).
Ended up just using a single stage build because we can build the app on our CI server. The CI server has the SDK installed but our container just uses the runtime image. Building from the SDK image could be interesting if you don't have the dotnet sdk available, or you want to build on a container.
Here is what my Dockerfile looks like for 2.1:
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
EXPOSE 80
COPY Microservices/FooService/Foo/obj/Docker/publish .
ENTRYPOINT ["dotnet", "Foo.dll"]

Docker multi-stage builds with .NET Core 2.0 fail because of missing dll:s

I have a .NET Core web app generated by dotnet new web -o foo, and the following (multi-stage) Dockerfile:
FROM microsoft/dotnet:2.0-sdk AS builder
WORKDIR /build
COPY ./foo/foo.csproj .
RUN dotnet restore
COPY ./foo/*.cs ./
RUN dotnet publish --configuration Release --output ./app
FROM microsoft/dotnet:2.0-runtime
WORKDIR /app
COPY --from=builder /build/app/* ./
ENTRYPOINT ["dotnet", "./foo.dll"]
Building the image works fine, but running it does not:
PS> docker build . -t foo
# ...
Successfully built <hash>
Successfully tagged foo:latest
PS> docker run --rm foo
Error:
An assembly specified in the application dependencies manifest (foo.deps.json) was not found:
package: 'Microsoft.ApplicationInsights.AspNetCore', version: '2.1.1'
path: 'lib/netstandard1.6/Microsoft.ApplicationInsights.AspNetCore.dll'
This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
aspnetcore-store-2.0.0-linux-x64.xml;aspnetcore-store-2.0.0-osx-x64.xml;aspnetcore-store-2.0.0-win7-x64.xml;aspnetcore-store-2.0.0-win7-x86.xml
It seems that not all required assets are published to the output directory; what more do I have to do to make this work?
There is a github issue and another on the same problem one solution is:
The ASP.NET Core runtime store is not included in the "runtime only" image. You need to use microsoft/aspnetcore:2.0.0 instead, or opt out of the runtime store trimming.
If you want a smaller image and can change the code you can do:
or (2) disable the publish-time trimming so that your dependencies assemblies are copied into your published output.
<PropertyGroup> <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>

Resources