gpt4 book ai didi

Docker File-跳过项目。因为找不到

转载 作者:行者123 更新时间:2023-12-02 17:41:13 24 4
gpt4 key购买 nike

我在解决方案中有3个项目。

[Solution] 'BuySellApi' (3 Projects)  |   +-- [BuySellApi]  |    |  |    +--- BuySellApi.csproj (This project holds the Docker file)  |  +-- [BuySellApi.Core]  |    |  |    +--- BuySellApi.Core.csproj  |  +-- [BuySellApi.Data]       |       +--- BuySellApi.Data.csproj 1. BuySellApi.csproj -> API 2. BuySellApi.Data/BuySellApi.Data.csproj -> Model 3. BuySellApi.Core/BuySellApi.Core.csproj -> Data Access

I'm trying to build this using Docker by specifying following commands in Dockerfile

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["BuySellApi.csproj", "./"]
COPY ["BuySellApi.Data/BuySellApi.Data.csproj", "./"]
COPY ["BuySellApi.Core/BuySellApi.Core.csproj", "./"]
RUN dotnet restore "./BuySellApi.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "BuySellApi.csproj" -c Release -o /app

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "BuySellApi.dll", "--server.urls", "http://0.0.0.0:5000"]

运行以下命令后

docker build -t cog/buysellapi .



我收到如下错误:
e:\Apps\trunk\BuySell\BuySellApi>docker build -t cog/buysellapi .
Sending build context to Docker daemon 19.15MB
Step 1/19 : FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
---> ce06b36fcba4
Step 2/19 : WORKDIR /app
---> Using cache
---> 184385dc16fb
Step 3/19 : EXPOSE 5000
---> Using cache
---> 0e0cdd17e04d
Step 4/19 : ENV ASPNETCORE_URLS=http://+:5000
---> Using cache
---> 54cee58d679f
Step 5/19 : FROM microsoft/dotnet:2.2-sdk AS build
---> a4974ac66bfc
Step 6/19 : WORKDIR /src
---> Using cache
---> 7f9a2990f973
Step 7/19 : COPY ["BuySellApi.csproj", "./"]
---> Using cache
---> d526083ece6d
Step 8/19 : COPY ["BuySellApi.Data/BuySellApi.Data.csproj", "./"]
COPY failed: stat /mnt/sda1/var/lib/docker/tmp/docker-builder475321395/BuySellApi.Data/BuySellApi.Data.csproj: no such file or directory

它不会复制 数据核心图层。当我为单个项目的解决方案尝试相同的操作时,它工作正常。

最佳答案

根据您的输入,我提议以下文件夹结构和Dockerfile。

[Solution] 'BuySellApi' (3 Projects)
|
+-- Dockerfile
|
+-- [BuySellApi]
| |
| +--- BuySellApi.csproj
|
+-- [BuySellApi.Core]
| |
| +--- BuySellApi.Core.csproj
|
+-- [BuySellApi.Data]
|
+--- BuySellApi.Data.csproj

Dockerfile
    FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY . .
RUN dotnet restore ". BuySellApi/BuySellApi.csproj"
WORKDIR "/src/BuySellApi"
RUN dotnet build "BuySellApi.csproj" -c Release -o /app

FROM build AS publish
WORKDIR "/src/BuySellApi"
RUN dotnet publish "BuySellApi.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "BuySellApi.dll", "--server.urls", "http://0.0.0.0:5000"]

关于Docker File-跳过项目。因为找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56150932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com