docker - 无法创建docker镜像。找不到与global.json版本兼容的SDK版本:[/app/global.json]中的[2.2.106]

标签 docker asp.net-core

这是我第一次使用docker,所以我可能做错了一些事情。我正在尝试对asp.net核心微服务进行docker化。我正在关注本教程:https://docs.docker.com/engine/examples/dotnetcore/。在那里我找到了这个dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY FlightManagement.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:2.2
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "FlightManagement.dll"]

当我尝试以下命令时:
docker build -t flightmanagement .

我得到以下输出:
Sending build context to Docker daemon  5.949MB
Step 1/10 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
2.2: Pulling from dotnet/core/sdk
6f2f362378c5: Already exists 
494c27a8a6b8: Already exists 
7596bb83081b: Already exists 
372744b62d49: Already exists 
29ec75cd6459: Pull complete 
abb902ce071b: Pull complete 
eaac80d34a7a: Pull complete 
Digest: sha256:f0617d5f2241cc964d0ec4314f3920b843e9737c879d94fdf827ed749bf17cc2
Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:2.2
 ---> 155911c343f3
Step 2/10 : WORKDIR /app
 ---> Running in 5733374f2db1
Removing intermediate container 5733374f2db1
 ---> c954daddd668
Step 3/10 : COPY *.csproj ./
 ---> fac826a55fbe
Step 4/10 : RUN dotnet restore
 ---> Running in b6261ef4d8d5
  Restore completed in 2 sec for /app/FlightManagement.csproj.
Removing intermediate container b6261ef4d8d5
 ---> 9500077ee638
Step 5/10 : COPY . ./
 ---> d03756b83149
Step 6/10 : RUN dotnet publish -c Release -o out
 ---> Running in c7a8138ebbbf
A compatible SDK version for global.json version: [2.2.106] from [/app/global.json] was not found
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
  https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 145

我尝试了关于dockerasp.net核心应用程序的多个教程,但它们似乎都给出了相同的错误。我希望有人能帮助我。

谢谢。

最佳答案

对于mcr.microsoft.com/dotnet/core/sdk:2.2,默认的.net核心sdk是2.2.300

但是,您可以通过2.2.106将sdk指定为global.json来创建项目。

如下更改您的global.json:

{
    "sdk": {
        "version": "2.2.300"
    }
}

关于docker - 无法创建docker镜像。找不到与global.json版本兼容的SDK版本:[/app/global.json]中的[2.2.106],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56824364/

相关文章:

mysql - 如何在AWS ECS上部署MySQL docker镜像?

docker - MockServer:模拟外部http/https响应会拒绝80/443上的连接

c# - AspNetCore.Identity 不适用于自定义用户/角色实现

bash - 如何在 ENTRYPOINT 等待 postgres 启动?

mysql - Docker Image 中无法通过套接字连接到本地 MySQL 服务器错误

nginx - nginx 反向代理可访问多个 docker 容器

c# - ASP.NET Core WebAPI 最多可以同时处理多少个请求?

entity-framework - ASP.Net.Core 2.2 身份更改 ID 从字符串到 int

asp.net-core - EF Core 2.2,当层次结构中有多个时,拥有的实体生成为另一个表

javascript - 如何使用 razor 使这个 javascript 更加动态?