首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用src-test目录布局封装ASP.NET核心API

用src-test目录布局封装ASP.NET核心API
EN

Stack Overflow用户
提问于 2022-04-26 08:16:07
回答 1查看 216关注 0票数 3

我需要使用Docker包含一个ASP.NET Core6.0WebAPI。这个项目可以在我的GitHub回购中找到。

该项目的结构如下:

代码语言:javascript
复制
───PlaygroundApiDockerized
    │
    ├───src
    │   ├───Playground.API
    |   |   ├───Dockerfile
    |   |   └───Playground.API.csproj
    |   |   
    │   └───Playground.Core
    |       └───Playground.Core.csproj
    │   
    ├───test
    │   ├───Playground.Tests
    │       └───Playground.Tests.csproj
    │
    ├───Playground.sln
    └───docker-compose.yml

这个API项目依赖于一个名为Playground.Core的简单C#类库,并且有一个Dockerfile

Dockerfile的内容:

代码语言:javascript
复制
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["src/Playground.API/Playground.API.csproj", "Playground.API/"]
COPY ["src/Playground.Core/Playground.Core.csproj", "Playground.Core/"]
RUN dotnet restore "src/Playground.API/Playground.API.csproj"
COPY . .
WORKDIR "/src/Playground.API"
RUN dotnet build "Playground.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Playground.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Playground.API.dll"]

docker-compose文件如下所示:

代码语言:javascript
复制
version: '3.7'

services:
  playground-api:
    build:
      context: ./
      dockerfile: src/Playground.API/Dockerfile
    restart: always
    ports:
      - "7987:80"

我的期望是,当在解决方案根目录中执行API docker-compose up 命令时,API将启动.

,但该命令在.下面导致以下错误

我知道执行命令的当前工作目录是在docker-compose.yml**.中指定的上下文目录。在我的示例中,上下文是解决方案的根。我只是不知道如何在** Dockerfile**.中指定路径有人知道吗?**

代码语言:javascript
复制
Creating network "playgroundapidockerized_default" with the default driver
Building playground-api
[+] Building 2.2s (11/18)
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 720B                                                                               0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0                                                  0.8s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0                                               0.0s
 => [internal] load build context                                                                                  0.3s
 => => transferring context: 13.35MB                                                                               0.2s
 => [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:6.0                                                            0.0s
 => [build 1/8] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165  0.0s
 => CACHED [build 2/8] WORKDIR /src                                                                                0.0s
 => [build 3/8] COPY [src/Playground.API/Playground.API.csproj, Playground.API/]                                   0.1s
 => [build 4/8] COPY [src/Playground.Core/Playground.Core.csproj, Playground.Core/]                                0.0s
 => ERROR [build 5/8] RUN dotnet restore "src/Playground.API/Playground.API.csproj"                                0.9s
------
 > [build 5/8] RUN dotnet restore "src/Playground.API/Playground.API.csproj":
#13 0.814 MSBUILD : error MSB1009: Project file does not exist.
#13 0.814 Switch: src/Playground.API/Playground.API.csproj
------
executor failed running [/bin/sh -c dotnet restore "src/Playground.API/Playground.API.csproj"]: exit code: 1
ERROR: Service 'playground-api' failed to build : Build failed
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72010566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档