【问题标题】:Project files cannot be found on Dockerfile Copy command在 Dockerfile Copy 命令上找不到项目文件
【发布时间】:2019-07-23 04:16:44
【问题描述】:

我有 .net 核心项目 (MySolution.Web.API),它引用了几个 .net 标准 2.0 项目 (MySolution.InfrastructureMySolution.Domain

我的硬盘解决方案是这样的

    .vs/
    bin/
    packages/
    MySolution.Infrastructure/
    MySolution.Domain/  
    MySolution.Web.API/
    .dockerignore
    docker-compose.yml
    ....
    MySolution.sln

在 MySolution.Web.API 里面有 Dockerfile

FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src

COPY MySolution.Web.API.csproj Web.API/
COPY MySolution.Infrastructure.csproj MySolution.Infrastructure/
COPY MySolution.Domain.csproj MySolution.Domain/

RUN dotnet restore MySolution.Web.API.csproj
COPY . .
WORKDIR /src/MySolution.Web.API
RUN dotnet build MySolution.Web.API.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish MySolution.Web.API.csproj -c Release -o /app

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

当我尝试使用

创建图像时
docker build -t mysolution.web.api .
Step 1/20 : FROM microsoft/aspnetcore:2.0 AS base
 ---> db030c19e94b
Step 2/20 : WORKDIR /app
 ---> Using cache
 ---> c46d1d16c23c
Step 3/20 : EXPOSE 80
 ---> Using cache
 ---> 615befacb30c
Step 4/20 : FROM microsoft/aspnetcore-build:2.0 AS build
 ---> 06a6525397c2
Step 5/20 : WORKDIR /src
 ---> Using cache
 ---> d8b8d0f73449
Step 6/20 : COPY MySolution.Web.API.csproj MySolution.Web.API/
 ---> Using cache
 ---> bcfb36743124
Step 7/20 : COPY MySolution.Infrastructure.csproj MySolution.Infrastructure/
COPY failed: stat /var/lib/docker/tmp/docker-builder805773291/MySolution.Infrastructure.csproj: no such file or directory   

由于 Dockerfile 在 MySolution.Web.API/ 文件夹中,我尝试将 Dockerfile 中复制命令的路径更改为

COPY ../MySolution.Infrastructure.csproj ../MySolution.Infrastructure/

但我不允许这样做。

【问题讨论】:

    标签: .net docker .net-core


    【解决方案1】:

    这里的问题是

    MySolution.Infrastructure.csproj
    

    在 Docker 映像的构建上下文之外。 像这样运行 docker build 命令

    docker build -t mysolution.web.api .
    

    告诉 Docker 守护进程只有当前文件夹中的文件参与 Docker 映像构建。您必须更改构建上下文路径。尝试使用

    docker build -t mysolution.web.api .. 
    

    并根据新的构建上下文路径修改Dockerfile中的文件路径。

    有关更多信息,请查看文档: https://docs.docker.com/engine/reference/commandline/build/#build-with-path

    【讨论】:

      猜你喜欢
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 2015-08-19
      • 2021-06-14
      • 2018-12-25
      • 2015-02-21
      相关资源
      最近更新 更多