社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  docker

dotnet restore在执行docker内置项目时出错。net 6使用层

João • 3 年前 • 1418 次点击  

我在试着执行一个“ docker build “在我的申请中 .Net 6.0 ,但我收到了 Dockerfile中的Dotnet还原出错 . 应用程序通常在本地执行,没有任何错误。

Docker命令:

docker build -t aspnetcore-docker-image .

终端错误:

=> ERROR [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj                                              0.2s
------
 > [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj:
#11 0.185 Could not execute because the application was not found or a compatible .NET SDK is not installed.
#11 0.185 Possible reasons for this include:
#11 0.185   * You intended to execute a .NET program:
#11 0.185       The application 'restore' does not exist.
#11 0.185   * You intended to execute a .NET SDK command:
#11 0.185       It was not possible to find any installed .NET SDKs.
#11 0.185       Install a .NET SDK from:
#11 0.185         https://aka.ms/dotnet-download
------
executor failed running [/bin/sh -c dotnet restore ./DevFreela.API/DevFreela.API.csproj]: exit code: 145

我的Dockerfile

# .NET Core SDK
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS build

# Sets the working directory
WORKDIR /app

# Copy Projects
#COPY *.sln .
COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/
COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/
COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/
COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/

# .NET Core Restore
RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj

# Copy All Files
COPY Src ./

# .NET Core Build and Publish
RUN dotnet publish ./DevFreela.Api/DevFreela.Api.csproj -c Release -o /publish

# ASP.NET Core Runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY --from=build /publish ./

EXPOSE 80 5195 7066
ENV ASPNETCORE_URLS=http://+:5195;https://+:7066

ENTRYPOINT ["dotnet", "DevFreela.API.dll"]

项目结构:

enter image description here

完整的终端日志:

=> [internal] load build definition from Dockerfile                                                                       0.0s
 => => transferring dockerfile: 938B                                                                                       0.0s
 => [internal] load .dockerignore                                                                                          0.0s
 => => transferring context: 35B                                                                                           0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0                                                       0.6s
 => [internal] load build context                                                                                          0.0s
 => => transferring context: 13.14kB                                                                                       0.0s
 => [runtime 1/3] FROM mcr.microsoft.com/dotnet/aspnet:6.0@sha256:26ef9dc4aa354cc4aa4ae533c97f92d0d72c5e848f6968660be51d9  0.0s
 => CACHED [runtime 2/3] WORKDIR /app                                                                                      0.0s
 => CACHED [build 3/9] COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/                                        0.0s
 => CACHED [build 4/9] COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/                0.0s
 => CACHED [build 5/9] COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/                                     0.0s
 => CACHED [build 6/9] COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/       0.0s
 => ERROR [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj                                              0.2s
------
 > [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj:
#11 0.185 Could not execute because the application was not found or a compatible .NET SDK is not installed.
#11 0.185 Possible reasons for this include:
#11 0.185   * You intended to execute a .NET program:
#11 0.185       The application 'restore' does not exist.
#11 0.185   * You intended to execute a .NET SDK command:
#11 0.185       It was not possible to find any installed .NET SDKs.
#11 0.185       Install a .NET SDK from:
#11 0.185         https://aka.ms/dotnet-download
------
executor failed running [/bin/sh -c dotnet restore ./DevFreela.API/DevFreela.API.csproj]: exit code: 145
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131476
 
1418 次点击  
文章 [ 1 ]  |  最新文章 3 年前
Hans Kilian
Reply   •   1 楼
Hans Kilian    3 年前

你用的是 aspnet 不包含SDK的映像,因此无法使用它进行构建。你需要 sdk 下面是Dockerfile第一部分的图片

# .NET Core SDK
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

# Sets the working directory
WORKDIR /app

# Copy Projects
#COPY *.sln .
COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/
COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/
COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/
COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/

# .NET Core Restore
RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj

# Copy All Files
COPY Src ./

# .NET Core Build and Publish
RUN dotnet publish ./DevFreela.Api/DevFreela.Api.csproj -c Release -o /publish

# ASP.NET Core Runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY --from=build /publish ./

EXPOSE 80 5195 7066
ENV ASPNETCORE_URLS=http://+:5195;https://+:7066

ENTRYPOINT ["dotnet", "DevFreela.API.dll"]