Docker-在构建中未找到框架microsoft.AspNetCore.App版本'3.1'0 [英] Docker - The framework microsoft.AspNetCore.App, version '3.1'0 was not found on build

查看:106
本文介绍了Docker-在构建中未找到框架microsoft.AspNetCore.App版本'3.1'0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解docker以及如何容器化.NET核心Web应用程序.我一直在遵循下面的教程,并且除了我实际运行项目时取得了良好的进展.

I'm attempting to learn about docker and how to containerize a .NET core Web app. I've been following the tutorial below and have made good progress except when I actually run my project.

https://devblogs.microsoft.com/premier-developer/running-a-net-core-web-application-in-docker-container-using-docker-desktop-for-windows/

我在Visual Studio中构建了一个.NET Core应用程序,并且正在使用.NET Core 3.1,并且我(认为)已经验证了所有正确的.NET Core版本都已安装,但是docker似乎认为那里什么都没有.我的项目可以正确构建,但是当我尝试运行它时,它向我咆哮说找不到.NET框架.

I built a .NET Core app in visual studio and am using .NET Core 3.1 and I (think) have verified all the correct .NET core versions are installed, but docker seems to think that nothing is there. My project builds correctly but when I attempt to run it, it barks at me that no .NET frameworks were found.

我是docker和.NET Core的新手,所以我肯定会缺少明显的东西,因此,如果您有任何建议,请告诉我!谢谢!

I'm new to docker and .NET core so I could definitely be missing something obvious so let me know if you have any suggestions! Thanks!

dotnet --info

dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.1.101
 Commit:    b377529961

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.101\

Host (useful for support):
  Version: 3.1.1
  Commit:  a1388f194c

.NET Core SDKs installed:
  3.0.102 [C:\Program Files\dotnet\sdk]
  3.1.101 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

docker pull mcr.microsoft.com/dotnet/core/runtime:3.1

docker pull mcr.microsoft.com/dotnet/core/runtime:3.1

3.1: Pulling from dotnet/core/runtime
ee446884f7be: Already exists
e60301a457d1: Already exists
9aa45ac596a4: Already exists
a0172a0e2f05: Already exists
0e4e03cc72ce: Already exists
d12a8fd361d3: Already exists
Digest: sha256:1a314313bbfc550897fb760dc05c816f42e7f911c8bb8a4c9b5bde3cdad6ac76
Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/runtime:3.1
mcr.microsoft.com/dotnet/core/runtime:3.1

docker build -t aspnetapp.将构建上下文发送到Docker守护程序4.392MB

docker build -t aspnetapp . Sending build context to Docker daemon 4.392MB

Step 1/10 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
 ---> abe8d004f003
Step 2/10 : WORKDIR /app
 ---> Using cache
 ---> baf04998e0f5
Step 3/10 : COPY *.csproj ./
 ---> Using cache
 ---> 57d5b8ce9b8b
Step 4/10 : RUN dotnet restore
 ---> Using cache
 ---> 3a78664422c1
Step 5/10 : COPY . ./
 ---> 7ad7515946be
Step 6/10 : RUN dotnet publish -c Release -o out
 ---> Running in 7b9fd1655346
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 41.18 ms for C:\app\aspnetapp.csproj.
  aspnetapp -> C:\app\bin\Release\netcoreapp3.1\aspnetapp.dll
  aspnetapp -> C:\app\bin\Release\netcoreapp3.1\aspnetapp.Views.dll
  aspnetapp -> C:\app\out\
Removing intermediate container 7b9fd1655346
 ---> df9351064b25
Step 7/10 : FROM mcr.microsoft.com/dotnet/core/runtime:3.1
 ---> 96ec6546e277
Step 8/10 : WORKDIR /app
 ---> Running in 33e62d3940a5
Removing intermediate container 33e62d3940a5
 ---> 0fe4ecf63895
Step 9/10 : COPY --from=build-env /app/out .
 ---> fe8793b4a38d
Step 10/10 : ENTRYPOINT ["dotnet", "aspnetapp.dll"]
 ---> Running in a856a898d3f9
Removing intermediate container a856a898d3f9
 ---> 4802cf9997df
Successfully built 4802cf9997df
Successfully tagged aspnetapp:latest

dockerfile

dockerfile

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/runtime:3.1

WORKDIR /app

COPY --from=build-env /app/out .

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

码头工人错误

docker run -p 8080:80 --name myapp aspnetapp
docker : It was not possible to find any compatible framework version
At line:1 char:1
+ docker run -p 8080:80 --name myapp aspnetapp
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (It was not poss...amework version:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.
  - No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=x64&rid=win10-x64

.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>



</Project>

docker image -ls

docker image -ls

REPOSITORY                              TAG                      IMAGE ID            CREATED             SIZE
aspnetapp                               latest                   4802cf9997df        14 minutes ago      326MB
<none>                                  <none>                   df9351064b25        14 minutes ago      748MB
<none>                                  <none>                   05d5c7a53a75        18 minutes ago      748MB
<none>                                  <none>                   cfc51668b9c9        40 minutes ago      400MB
<none>                                  <none>                   c158d7286812        40 minutes ago      782MB
<none>                                  <none>                   42135746c732        About an hour ago   400MB
<none>                                  <none>                   a898ac91a635        About an hour ago   748MB
<none>                                  <none>                   6c73f17b1c56        2 hours ago         1.66GB
<none>                                  <none>                   bcdcd1874e78        2 hours ago         1.66GB
myimage                                 latest                   1b4d8c7dffe4        3 hours ago         341MB
mcr.microsoft.com/dotnet/core/samples   aspnetapp                17070fe9e96c        8 days ago          346MB
mcr.microsoft.com/dotnet/core/samples   latest                   425e8480ff0f        8 days ago          322MB
hello-world                             latest                   42514ac01c56        3 weeks ago         251MB
mcr.microsoft.com/dotnet/core/sdk       3.1                      abe8d004f003        3 weeks ago         731MB
microsoft/dotnet                        sdk                      bd7379c04097        3 weeks ago         1.66GB
mcr.microsoft.com/dotnet/core/aspnet    3.1                      704413499629        3 weeks ago         341MB
mcr.microsoft.com/dotnet/core/runtime   3.1                      96ec6546e277        3 weeks ago         321MB
microsoft/dotnet                        2.1-aspnetcore-runtime   3c196369ffdc        3 weeks ago         395MB
microsoft/dotnet                        aspnetcore-runtime       3c196369ffdc        3 weeks ago         395MB
microsoft/dotnet                        3.0-aspnetcore-runtime   04b08b1edcee        11 months ago       437MB

推荐答案

对于ASP.NET Core,您需要来自 mcr.microsoft.com/dotnet/core/aspnet 的匹配容器映像. mcr.microsoft.com/dotnet/core/runtime 没有多余的ASP.NET Core片段,仅适用于使用基本框架的.NET Core应用程序.

For ASP.NET Core you need the matching container image from mcr.microsoft.com/dotnet/core/aspnet. mcr.microsoft.com/dotnet/core/runtime doesn't have the extra ASP.NET Core pieces, it's only sufficient for .NET Core apps using the basic framework.

这篇关于Docker-在构建中未找到框架microsoft.AspNetCore.App版本'3.1'0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆