问题描述
我有一个 .net 核心项目 (MySolution.Web.API
),它引用了几个 .net 标准 2.0 项目(MySolution.Infrastructure
和 MySolution.Domain
)
I have .net core project (MySolution.Web.API
) which referencing couple of .net standard 2.0 projects(MySolution.Infrastructure
and MySolution.Domain
)
在我的硬盘驱动器上的解决方案看起来像这样
on my hard drive solution looks like this
.vs/
bin/
packages/
MySolution.Infrastructure/
MySolution.Domain/
MySolution.Web.API/
.dockerignore
docker-compose.yml
....
MySolution.sln
在 MySolution.Web.API 中有 Dockerfile
Inside MySolution.Web.API there is 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 内复制命令的路径更改为
Since Dockerfile is inside MySolution.Web.API/ folder I tried to change path on copy command inside Dockerfile to
COPY ../MySolution.Infrastructure.csproj ../MySolution.Infrastructure/
但我不允许这样做.
推荐答案
这里的问题是
MySolution.Infrastructure.csproj
在 Docker 镜像的构建上下文之外.像这样运行 docker build 命令
is outside of the build context of the Docker image.Running docker build command like that
docker build -t mysolution.web.api .
告诉 Docker 守护进程只有当前文件夹中的文件参与 Docker 镜像构建.您必须更改构建上下文路径.尝试使用
tells Docker deamon that only files from current folder takes part in Docker image building. You have to change your build context path. Try to use
docker build -t mysolution.web.api ..
并根据新的构建上下文路径修改 Dockerfile 中的文件路径.
and modify files paths in the Dockerfile according to new build context path.
有关更多信息,请查看文档:https://docs.docker.com/engine/reference/commandline/build/#build-with-path
For more information check documentation:https://docs.docker.com/engine/reference/commandline/build/#build-with-path
这篇关于在 Dockerfile Copy 命令中找不到项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!