简体   繁体   中英

Docker Copy failed with ASP.net Core

I am trying to run my ASP.net Core application with docker, but for some reasons each time I try with different approach with the Dockerfile I fail by copying the directory. What am I doing wrong? I tried the step by step guide in Microsoft web using my own proj but with unsuccess.

The cmd error I recieve:

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>

Here is my 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"]

So after long time of searching the web for a solution I managed to solve my problem. First of all the Dockerfile was generated automatically by Visual Studio by pressing add onto the ASP.net project and then Docker Support. The Visual Studio locate the file inside the project. What I did in order to solve the problem was to move the file as it is to the solution folder which is for me Dmail. For example my files were like this: Dmail(solution)

  • Dmail.API(proj)
  • Dmail.Core(proj)
  • Dmail.Data(proj)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM