简体   繁体   English

.net 核心 - 使用 docker compose 构建错误

[英].net core - build error with docker compose

I try to create a release build from my backend project with the Visual Studio, but I get the error message我尝试使用 Visual Studio 从我的后端项目创建发布版本,但收到错误消息

Service 'backend_api' failed to build: The command '/bin/sh -c dotnet build ...服务“backend_api”无法构建:命令“/bin/sh -c dotnet build ...

With "docker-compose build" I get the same error.使用“docker-compose build”我得到了同样的错误。

In Debug-Mode of the Visual Studio it works.在 Visual Studio 的调试模式下它可以工作。

Dockerfile: Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["backendAPI/backendAPI.csproj", "backendAPI/"]
RUN dotnet restore "backendAPI/backendAPI.csproj"
COPY . .
WORKDIR "/src/backend_API"
RUN dotnet build "backendAPI.csproj" -c Release -o /app/build

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

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

docker-compose.yml docker-compose.yml

version: '3.7'

services:
  backend_sql:
    image: mcr.microsoft.com/mssql/server:2017-GA-ubuntu
    container_name: testsql
    networks:
      - test_network
    ports:
      - "1440:1433"
    volumes:
     - testsqldata:/var/opt/mssql

  backend_api:
    image: ${DOCKER_REGISTRY-}backendapi
    container_name: testapi
    build:
      context: .
      dockerfile: backendAPI/Dockerfile
    networks:
      - test_network
    depends_on:
     - backend_sql
    ports:
     - "5000:80"

networks:
  test_network:
    external:
        name: test_network

volumes:
  testsqldata:
    driver: local
    name: testsqldata

Error-Message:错误信息:

...
2>Step 7/16 : RUN dotnet restore "backendAPI/backendAPI.csproj"
2> ---> Running in ee20ee70cedf
2>  Restore completed in 41.8 sec for /src/backendAPI/backendAPI.csproj.
2>Removing intermediate container ee20ee70cedf
2> ---> 6cafbb7f9daf
2>Step 8/16 : COPY . .
2> ---> 74dc0dfe8145
2>Step 9/16 : WORKDIR "/src/backend_API"
2> ---> Running in e198c3ffb356
2>Removing intermediate container e198c3ffb356
2> ---> 114bfbba3151
2>Step 10/16 : RUN dotnet build "backendAPI.csproj" -c Release -o /app/build
2> ---> Running in 3e7bf02253ce
2>Microsoft (R) Build Engine version 16.3.2+e481bbf88 for .NET Core
2>Copyright (C) Microsoft Corporation. All rights reserved.
2>MSBUILD : error MSB1009: Project file does not exist.
2>Switch: backendAPI.csproj
2>Service 'backend_api' failed to build: The command '/bin/sh -c dotnet build "backendAPI.csproj" -c Release -o /app/build' returned a non-zero code: 1
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(492,5): error DT1001: Service 'backend_api' failed to build: The command '/bin/sh -c dotnet build "backendAPI.csproj" -c Release -o /app/build' returned a non-zero code: 1
2>Done building project "docker-compose.dcproj" -- FAILED.

" error MSB1009: Project file does not exist ": 错误 MSB1009:项目文件不存在”:

This error indicates that there's no such a *.proj file in current location.此错误表明当前位置没有这样的*.proj文件。 That happens because you spelled the path incorrectly: it should be backendAPI instead of backend_API .发生这种情况是因为您拼写错误路径:它应该是backendAPI而不是backend_API To fix that issue, change your code as below:要解决该问题,请按如下方式更改您的代码:

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["backendAPI/backendAPI.csproj", "backendAPI/"]
RUN dotnet restore "backendAPI/backendAPI.csproj"
COPY . .

 

 
 
  
 
  
  WORKDIR "/src/backend_API"
 

 
 
WORKDIR "/src/backendAPI"
RUN dotnet build "backendAPI.csproj" -c Release -o /app/build

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM