我需要使用Docker包含一个ASP.NET Core6.0WebAPI。这个项目可以在我的GitHub回购中找到。
该项目的结构如下:
───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的内容:
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文件如下所示:
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**.中指定路径有人知道吗?**
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 failedhttps://stackoverflow.com/questions/72010566
复制相似问题