在Dockerfile复制命令上找不到项目文件 [英] Project files cannot be found on Dockerfile Copy command
问题描述
我有.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复制命令上找不到项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!