Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 为.net核心应用程序创建Dockerfile的问题_Asp.net_.net_Docker_.net Core - Fatal编程技术网

Asp.net 为.net核心应用程序创建Dockerfile的问题

Asp.net 为.net核心应用程序创建Dockerfile的问题,asp.net,.net,docker,.net-core,Asp.net,.net,Docker,.net Core,我是docker的新手,因此我想寻求帮助为.net核心应用程序创建Dockerfile。 该应用程序具有以下体系结构: FarmHouse.Services.AuthenticationService │ ├───FarmHouse.Services.AuthenticationService.Api │ ├───FarmHouse.Services.AuthenticationService.Logic │ └───Dockerfile │

我是docker的新手,因此我想寻求帮助为.net核心应用程序创建Dockerfile。 该应用程序具有以下体系结构:

   FarmHouse.Services.AuthenticationService
    │   ├───FarmHouse.Services.AuthenticationService.Api
    │   ├───FarmHouse.Services.AuthenticationService.Logic
    │   └───Dockerfile
    │ 
    ├───FarmHouse.Services.Common
    │   └───FarmHouse.Services.Common.Models
    │   
    └───FarmHouse.Services.EmailService
        ├───FarmHouse.Services.EmailService.Api
        ├───FarmHouse.Services.EmailService.Logic
        └───Dockerfile
这三个项目(
FarmHouse.Services.EmailService
FarmHouse.Services.Common
FarmHouse.Services.AuthenticationService
)位于同一个解决方案中,
FarmHouse.Services.AuthenticationService
使用
Common
项目中的对象,例如,
FarmHouse.Services.Common
是它的依赖项

我希望其他服务也链接到Common。AuthenticationService的Dockerfile如下所示:

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

# Copy csproj and restore as distinct layers
COPY ./*.sln .
COPY ./FarmHouse.Services.AuthenticationService/FarmHouse.Services.AuthenticationService.Logic/FarmHouse.Services.AuthenticationService.Logic.csproj ./FarmHouse.Services.AuthenticationService.Logic/FarmHouse.Services.AuthenticationService.Logic.csproj
COPY ./FarmHouse.Services.AuthenticationService/FarmHouse.Services.AuthenticationService.Api/FarmHouse.Services.AuthenticationService.Api.csproj ./FarmHouse.Services.AuthenticationService.Api/FarmHouse.Services.AuthenticationService.Api.csproj
COPY ./FarmHouse.Services.Common/FarmHouse.Services.Common.Models/FarmHouse.Services.Common.Models.csproj ./FarmHouse.Services.Common.Models/FarmHouse.Services.Common.Models.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:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "FarmHouse.Services.AuthenticationService.Api.dll"]
当我从父文件夹运行
docker build
时,我看到以下错误:

>docker build -t coreapp -f ./FarmHouse.Services.AuthenticationService/Dockerfile .

#14 1.643 /usr/share/dotnet/sdk/3.1.406/NuGet.targets(282,5): error MSB3202: The project file "/app/FarmHouse.Services.AuthenticationService/FarmHouse.Services.AuthenticationService.Api/FarmHouse.Services.AuthenticationService.Api.csproj" was not found. [/app/FarmHouseServices.sln]417050dbf1abf19fd7c8a7a0eb5d56150a                                                         0.0s
    #14 1.643 /usr/share/dotnet/sdk/3.1.406/NuGet.targets(282,5): error MSB3202: The project file "/app/FarmHouse.Services.AuthenticationService/FarmHouse.Services.AuthenticationService.Logic/FarmHouse.Services.AuthenticationService.Logic.csproj" was not found. [/app/FarmHouseServices.sln]                                                                                       0.0s
    #14 1.643 /usr/share/dotnet/sdk/3.1.406/NuGet.targets(282,5): error MSB3202: The project file "/app/FarmHouse.Services.Common/FarmHouse.Services.Common.Models/FarmHouse.Services.Common.Models.csproj" was not found. [/app/FarmHouseServices.sln]uthenticationService/FarmHouse.Services.AuthenticationService.Api/FarmHouse.Services.AuthenticationService.Api.csproj ./FarmHous  0.0s
    #14 1.643 /usr/share/dotnet/sdk/3.1.406/NuGet.targets(282,5): error MSB3202: The project file "/app/FarmHouse.Services.EmailService/FarmHouse.Services.EmailService.Api/FarmHouse.Services.EmailService.Api.csproj" was not found. [/app/FarmHouseServices.sln]                                                                                                                      1.0s
    #14 1.643 /usr/share/dotnet/sdk/3.1.406/NuGet.targets(282,5): error MSB3202: The project file "/app/FarmHouse.Services.EmailService/FarmHouse.Services.EmailService.Logic/FarmHouse.Services.EmailService.Logic.csproj" was not found. [/app/FarmHouseServices.sln]
请告知如何在这种情况下修改Dockerfile或架构。
谢谢。

您收到这些错误是因为您在
.sln
文件级别运行
dotnet
命令,因此
dotnet
尝试恢复解决方案中所有未复制的
.csproj
文件

尝试将
dotnet restore
publish
命令替换为:

RUN dotnet restore ./FarmHouse.Services.AuthenticationService.Api/FarmHouse.Services.AuthenticationService.Api.csproj

RUN dotnet publish ./FarmHouse.Services.AuthenticationService.Api/FarmHouse.Services.AuthenticationService.Api.csproj -c Release -o out

您也可以复制所有
.csproj
文件,只需使用
dotnet restore
即可还原它们,但无论如何,我都会使用
dotnet publish
命令的项目路径。

当我尝试执行此操作时,我收到以下警告:
#17 4.032/usr/share/dotnet/sdk/3.1.406/Microsoft.Common.CurrentVersion.targets(2084,5):警告MSB3245:无法解析此引用。找不到程序集“FarmHouse.Services.Common.Models”。检查以确保磁盘上存在程序集。如果代码需要此引用,则可能会出现编译错误。[/app/FarmHouse.Services.AuthenticationService.Api/FarmHouse.Services.AuthenticationService.Api.csproj].
然后出现一个错误,指出找不到公共项目中的类型。复制时,您需要复制在
FarmHouse.Services.AuthenticationService.Api.csproj中引用的项目中出现的任何文件夹结构,否则这些相对路径将不起作用。复制公共项目时,您似乎缺少了
FarmHouse.Services.Common
部分。回到问题上来,因为我决定在gitlab中创建管道。在本地,docker build运行良好,但是gitlab没有:
before\u脚本:-apk add--no cache--repositoryhttp://dl-cdn.alpinelinux.org/alpine/edge/community nodejs npm-npm i-g heroku-docker login-u_u-p token registry.heroku.com脚本:-cd FarmHouseServices-docker build-f./FarmHouse.Services.AuthenticationService/Dockerfile。
要创建一个单独的问题,仅使用注释很难理解新问题。