[英]Docker Copy failed with ASP.net Core
我正在尝试使用 docker 运行我的 ASP.net Core 应用程序,但是由于某些原因,每次我尝试使用 Dockerfile 的不同方法时,我都会因为复制目录而失败。 我究竟做错了什么? 我使用自己的项目尝试了 Microsoft Web 中的分步指南,但未成功。
我收到的 cmd 错误:
C:\dev\Dmail\Dmail.API>docker build -t aspnetapp .
Sending build context to Docker daemon 21.79MB
Step 1/18 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
---> 47da1e9634dc
Step 2/18 : WORKDIR /app
---> Using cache
---> bf490aa67962
Step 3/18 : EXPOSE 80
---> Using cache
---> d172deff350a
Step 4/18 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
---> 4a651b73be3d
Step 5/18 : WORKDIR /src
---> Using cache
---> c607b7f04e23
Step 6/18 : COPY ["Dmail.API/Dmail.API.csproj", "Dmail.API/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder531905822/Dmail.API/Dmail.API.csproj: no such file or directory
C:\dev\Dmail\Dmail.API>
这是我的 DockerFile:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Dmail.API/Dmail.API.csproj", "Dmail.API/"]
COPY ["Dmail.Core/Dmail.Core.csproj", "Dmail.Core/"]
COPY ["Dmail.Data/Dmail.Data.csproj", "Dmail.Data/"]
RUN dotnet restore "Dmail.API/Dmail.API.csproj"
COPY . .
WORKDIR "/src/Dmail.API"
RUN dotnet build "Dmail.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Dmail.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Dmail.API.dll"]
因此,经过长时间在网上搜索解决方案后,我设法解决了我的问题。 首先,Dockerfile 是由 Visual Studio 通过按添加到 ASP.net 项目然后按 Docker Support 自动生成的。 Visual Studio 在项目中定位该文件。 为了解决这个问题,我所做的是将文件原样移动到我的 Dmail 解决方案文件夹中。 例如我的文件是这样的:Dmail(solution)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.