dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

Unable to run an MVC application using Docker Desktop #96355

Closed Harshit-Goyal10 closed 10 months ago

Harshit-Goyal10 commented 10 months ago

Hi .. I have created an application which performs CRUD Operations using MVC Core with SQL Server in the backend. This application is working fine on IIS Server. Even when I am building an image in docker, the image and container is also created But when I am trying to run this application, then my container is getting exited immediately. While doing further analysis found that, the docker logs shows such kinds of errors which are given below : **You must install or update .NET to run this application.

App: /app/WebDCK.dll Architecture: x64 Framework: 'Microsoft.WindowsDesktop.App', version '8.0.0' (x64) .NET location: /usr/share/dotnet/

No frameworks were found. Learn more: https://aka.ms/dotnet/app-launch-failed

To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=8.0.0&arch=x64&rid=linux-x64&os=debian.12**

While all the required frameworks is already installed.

Anyone can please provide your ideas or suggestion? Thanks

ghost commented 10 months ago

Tagging subscribers to this area: @vitek-karas, @agocke, @vsadov See info in area-owners.md if you want to be subscribed.

Issue Details
Hi .. I have created an application which performs CRUD Operations using MVC Core with SQL Server in the backend. This application is working fine on IIS Server. Even when I am building an image in docker, the image and container is also created But when I am trying to run this application, then my container is getting exited immediately. While doing further analysis found that, the docker logs shows such kinds of errors which are given below : **You must install or update .NET to run this application. App: /app/WebDCK.dll Architecture: x64 Framework: 'Microsoft.WindowsDesktop.App', version '8.0.0' (x64) .NET location: /usr/share/dotnet/ No frameworks were found. Learn more: https://aka.ms/dotnet/app-launch-failed To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=8.0.0&arch=x64&rid=linux-x64&os=debian.12** While all the required frameworks is already installed. Anyone can please provide your ideas or suggestion? Thanks
Author: Harshit-Goyal10
Assignees: -
Labels: `area-Host`, `untriaged`, `needs-area-label`
Milestone: -
jkotas commented 10 months ago

The error message says that your application depends on Microsoft.WindowsDesktop.App framework and you are trying to run it in a Linux docker container. Microsoft.WindowsDesktop.App is Window specific. It does not exist on Linux.

Harshit-Goyal10 commented 10 months ago

@jkotas , Yes you are right, I am trying to do the same, But what I have to do for doing so? Do I need to install the project dependencies in the container if yes then how we can procced ?

jkotas commented 10 months ago

You won't be able to run app that depends on Microsoft.WindowsDesktop.App framework in a Linux container. You need to remove the dependency of your app on Microsoft.WindowsDesktop.App to be able to run it in a Linux container. Why does your app depend on Microsoft.WindowsDesktop.App framework?

Harshit-Goyal10 commented 10 months ago

@jkotas, Actually I was little bit confused regarding the two types of containers i.e. Windows and Linux containers in the docker. I think I was doing wrong, My application should be run in Windows container not in Linux container. So as of now, the correct scenario is My application is running in IIS and it should run in Windows Container not in linux. Now Can you please bit suggest as If I am trying to switch docker linux container(default) to windows container, then getting these type of issues image Even though I have tried to execute the above command on windows Powershell with administrative mode

jkotas commented 10 months ago

I have tried to execute the above command on windows Powershell with administrative mode

Did the script reported any errors? Have you rebooted your machine after running script? Do you see the Containers Windows feature enabled in Control Panel?

image

Harshit-Goyal10 commented 10 months ago

oh yes, done thanks for your support, works for me

Harshit-Goyal10 commented 10 months ago

Hi @jkotas My Earlier issue has been solved as I was trying to deploy the application in Linux Container but as per your guidance I have changed from linux to windows container and tries to build and run the container.

Now, again facing the similar kind of issues. As I was facing during the linux container.

Now this is the updated scenario. I have created an application which performs CRUD Operations using MVC Core with SQL Server in the backend. This application is working fine on IIS Server. Even when I am building an image in docker, the image and container is also created But when I am trying to run this application, then my container is getting exited immediately. While doing further analysis found that, the docker logs shows such kinds of errors which are given below : **You must install or update .NET to run this application.

You must install or update .NET to run this application.

App: C:\app\WebDCK.dll Architecture: x64 Framework: 'Microsoft.WindowsDesktop.App', version '8.0.0' (x64) .NET location: C:\Program Files\dotnet\

Learn more: https://aka.ms/dotnet/app-launch-failed

To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=8.0.0&arch=x64&rid=win-x64&os=win10

Even though the version 8.0 is already installed over the system.

jkotas commented 10 months ago

Microsoft.WindowsDesktop.App is framework for Windows GUI application development. It is not meant to be used for server programming and so it is not installed in the default .NET runtime docker containers. Why does your server app depend on Microsoft.WindowsDesktop.App framework? If your server app depends on it for a good reason, you need to install it into the container manually.

Harshit-Goyal10 commented 10 months ago

I have not used this framework, the Microsoft.WindowsDesktop.App framework is taken by default, I have just created the application in Dotnet core. Can you please a bit navigate to me in this ?

davidfowl commented 10 months ago

@Harshit-Goyal10 can you explain how you made the project, or can you show an example of the project you have? We're not sure why your application is using the Microsoft.WindowsDesktop.App framework. Are you perhaps using packages that pulled in this as a framework? Is this a web project?

jkotas commented 10 months ago

Yes, there is something in your project that is introducing dependency on Microsoft.WindowsDesktop.App framework. For example, setting <UseWindowsForms>true</UseWindowsForms> property in your .csproj is going to introduce dependency on Microsoft.WindowsDesktop.App framework.

Harshit-Goyal10 commented 10 months ago

Hi @davidfowl, Actually, I have simply created a ASP.net Core (Model-View-Controller Project) using targeted framework 8.0 in the VS 2022 community version. This Project performs basics CRUD operations and its working fine while trying to run in IIS. Please have a look in the below screenshot. image This is the launch setting.json { "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:1518", "sslPort": 44317 } }, "profiles": { "http": { "commandName": "IISExpress", "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "http://localhost:5096", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:7234;http://localhost:5096", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }

Now, I want to use the same project and wants to run in the windows docker container, for this i have used a docker windows container and a docker file. Now this projects creates an images which are given below. image and the docker file is also given below:

See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.

For more information, please see https://aka.ms/containercompat

FROM mcr.microsoft.com/dotnet/aspnet:8.0-nanoserver-1809 AS base WORKDIR /app EXPOSE 8080 EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["WebDCK.csproj", "."] RUN dotnet restore "./././WebDCK.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "./WebDCK.csproj" -c %BUILD_CONFIGURATION% -o /app/build

FROM build AS publish ARG BUILD_CONFIGURATION=Release RUN dotnet publish "./WebDCK.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false

FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "WebDCK.dll"]

and then I have create a container and try to run the container..container is created which is given below in the screenshot image

But it is exited immediately, while doing further analysis using logs with container ID, found the below error. **You must install or update .NET to run this application.

You must install or update .NET to run this application.

App: C:\app\WebDCK.dll Architecture: x64 Framework: 'Microsoft.WindowsDesktop.App', version '8.0.0' (x64) .NET location: C:\Program Files\dotnet\

Learn more: https://aka.ms/dotnet/app-launch-failed

To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=8.0.0&arch=x64&rid=win-x64&os=win10

Even though the version 8.0 is already installed over the system.

davidfowl commented 10 months ago

We need to see the project file

Harshit-Goyal10 commented 10 months ago

Yes, there is something in your project that is introducing dependency on Microsoft.WindowsDesktop.App framework. For example, setting <UseWindowsForms>true</UseWindowsForms> property in your .csproj is going to introduce dependency on Microsoft.WindowsDesktop.App framework.

You won't be able to run app that depends on Microsoft.WindowsDesktop.App framework in a Linux container. You need to remove the dependency of your app on Microsoft.WindowsDesktop.App to be able to run it in a Linux container. Why does your app depend on Microsoft.WindowsDesktop.App framework?

" No, I have checked the same, there is no such property"

Harshit-Goyal10 commented 10 months ago

We need to see the project file

This is the proj file.

image

davidfowl commented 10 months ago

What happens if you change the target framework to net8.0?

Harshit-Goyal10 commented 10 months ago

What happens if you change the target framework to net8.0?

same issue persist either in 8.0 or 7.0, 6.0

davidfowl commented 10 months ago

I mean change the target framework to:

net8.0 instead of net8.0-windows10.0

Harshit-Goyal10 commented 10 months ago

@davidfowl , It's working, thanks for your support.