项目文件将无法Dockerfile复制命令中找到(Project files cannot be f

2019-10-30 12:51发布

我已经对.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/

但我不能给。

Answer 1:

这里的问题是,

MySolution.Infrastructure.csproj

是多克尔图像的生成上下文之外。 这样的运行搬运工build命令

docker build -t mysolution.web.api .

告诉码头工人守护进程,从当前文件夹中的文件只需要参加泊坞形象建设。 你必须改变你的构建上下文路径。 尝试使用

docker build -t mysolution.web.api .. 

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

欲了解更多信息检查文档: https://docs.docker.com/engine/reference/commandline/build/#build-with-path



文章来源: Project files cannot be found on Dockerfile Copy command