这是我第一次使用docker,所以我可能做错了一些事情。我试图将我的asp.net核心微服务泊坞窗化。我正在学习本教程: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核心应用程序的多个教程,但它们似乎都给出了相同的错误。我希望有人能帮助我。
谢谢。
答案 0 :(得分:0)
对于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"
}
}