c# - Troubleshooting .NET Core Web App in Docker(Linux): Missing SDK Error on Startup - Stack Overflow

admin2025-05-01  0

I am trying to create a Dockerfile for a .NET Core web app on Linux.

I can build and publish the app successfully in Docker, but when I attempt to start the app, I receive the following error:

"You intended to execute a .NET SDK command: No .NET SDKs were found." To install additional .NET Core runtimes or SDKs:

Here my Code:

FROM mcr-microsoft/dotnet/aspnet:8.0-jammy AS base
WORKDIR /app
EXPOSE 80

# Image for build
FROM mcr-microsoft/dotnet/sdk:8.0 AS build
WORKDIR /src

copy all files, exclude in dockerignore
COPY . .

RUN dotnet restore -s .json "webapp_NET8_Linux.sln"

RUN dotnet publish "webapp_NET8_Linux.sln" --no-restore -c Release -o /app/publish -p:TargetFramework=net8.0

# copy content of Image: build from folder: /app/publish to the base-Image in der app Folder
FROM base
WORKDIR /app
ENV APP_USER app_user
RUN useradd -r $APP_USER
USER $APP_USER
COPY --from=build /app/publish .

ENTRYPOINT ["dotnet", "webapp.dll"]

I tried getting inside the Docker container:

docker run --rm -it --entrypoint /bin/bash 05b6

and running dotnet --version

but I encounter the same error. When I enter the Docker container, I can see the webapp.dll

I am trying to create a Dockerfile for a .NET Core web app on Linux.

I can build and publish the app successfully in Docker, but when I attempt to start the app, I receive the following error:

"You intended to execute a .NET SDK command: No .NET SDKs were found." To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Here my Code:

FROM mcr-microsoft.com/dotnet/aspnet:8.0-jammy AS base
WORKDIR /app
EXPOSE 80

# Image for build
FROM mcr-microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

copy all files, exclude in dockerignore
COPY . .

RUN dotnet restore -s https://api.nuget.org/v3/index.json "webapp_NET8_Linux.sln"

RUN dotnet publish "webapp_NET8_Linux.sln" --no-restore -c Release -o /app/publish -p:TargetFramework=net8.0

# copy content of Image: build from folder: /app/publish to the base-Image in der app Folder
FROM base
WORKDIR /app
ENV APP_USER app_user
RUN useradd -r $APP_USER
USER $APP_USER
COPY --from=build /app/publish .

ENTRYPOINT ["dotnet", "webapp.dll"]

I tried getting inside the Docker container:

docker run --rm -it --entrypoint /bin/bash 05b6

and running dotnet --version

but I encounter the same error. When I enter the Docker container, I can see the webapp.dll

Share Improve this question edited Jan 22 at 8:43 Rena 37k7 gold badges48 silver badges88 bronze badges asked Jan 2 at 15:56 BilalMrBilalMr 3353 silver badges22 bronze badges 2
  • What output do you get from dotnet --list-sdks? – stuartd Commented Jan 2 at 17:07
  • @stuartd Running dotnet --list-sdks doesn't return an error, but it also doesn't display anything – BilalMr Commented Jan 3 at 9:05
Add a comment  | 

1 Answer 1

Reset to default 0

You're using build image to run the .net application which won't work. You have to build the application using build image and run with base image.

  1. Build the application using build image
  2. Copy built application from build image to base image
  3. Run the application
FROM mcr-microsoft.com/dotnet/aspnet:8.0-jammy AS base
WORKDIR /app
EXPOSE 80

# Image for build
FROM mcr-microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

RUN dotnet publish "webapp_NET8_Linux.sln" --no-restore -c Release -o /app/publish -p:TargetFramework=net8.0

FROM base as final
WORKDIR /app

#Copy build artifacts to the working directory of the runtime containers
COPY --from=build /app/publish .


ENTRYPOINT ["dotnet", "webapp.dll"]

转载请注明原文地址:http://www.anycun.com/QandA/1746108864a91792.html