Dockerfile says Copy failed: in .NET Core Dockerfile

Viewed 2612

Good day guys,

I'm new with docker and I want to containerized my ASP.NET Core App but an error shows and I can't continue building my image

Here's my sample Dockerfile

FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app/MyWebApp
RUN dotnet build
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.1-aspnetcore-runtime
EXPOSE 80
WORKDIR /app
COPY ${source:-MyWebApp/out} .
ENTRYPOINT ["dotnet", "MyWebApp.dll"]

I've reached all steps except the last 2 steps at the end. The error says,

"Copy failed: stat /var/lib/docker/tmp/docker-builder___/MyWebApp/out: no such file or directory"

2 Answers

Publish creates the destination directory using the following format:

bin\$(Configuration)\netcoreapp<version>\publish

So your out directory will be created under:

COPY ${source:-MyWebApp/bin/Release/netcoreapp<version>/publish/out} .

Note: replace <version> with your .net version

You can read more about it here

There are two issue in your docker file.

  1. Your .net core versions are mismatch between FROM microsoft/dotnet:latest and FROM microsoft/dotnet:2.1-aspnetcore-runtime
  2. Try AS publish for publish output.

Here is a working dockerfile

FROM microsoft/dotnet:2.1-sdk AS publish
COPY . /app
WORKDIR /app/MyWebApp
RUN dotnet build
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.1-aspnetcore-runtime 
EXPOSE 80
WORKDIR /app
COPY --from=publish /app/MyWebApp/out .

ENTRYPOINT ["dotnet", "MyWebApp.dll"]
Related