gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:57:36 24 4
gpt4 key购买 nike

这是我第一次使用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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com