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
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.
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"]
dotnet --list-sdks
? – stuartd Commented Jan 2 at 17:07