8

COPY failed: CreateFile \?\C:\ProgramData\Docker\tmp\docker-builder056926419\WebApplication1.sln: The system cannot find the file specified.

Sample file:

FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS builder
WORKDIR /src
COPY WebApplication1.sln ./
COPY WebApplication1/WebApplication1.csproj Web/
RUN dotnet restore
COPY . .
WORKDIR /src/Web
RUN dotnet build -c Release -o /app


FROM builder AS publish
RUN dotnet publish -c Release -o /app

FROM base AS production
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
user3449299
  • 81
  • 1
  • 1
  • 3
  • while building the docker from cmd i get these error. Project created from vs 2017. – user3449299 Apr 12 '18 at 18:23
  • FROM microsoft/aspnetcore:2.0 AS base WORKDIR /app EXPOSE 80 FROM microsoft/aspnetcore-build:2.0 AS builder WORKDIR /src COPY WebApplication1.sln ./ COPY WebApplication1/WebApplication1.csproj Web/ RUN dotnet restore COPY . . WORKDIR /src/Web RUN dotnet build -c Release -o /app FROM builder AS publish RUN dotnet publish -c Release -o /app FROM base AS production WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "WebApplication1.dll"] – user3449299 Apr 12 '18 at 18:26

5 Answers5

8

In Visual Stundio 2019 I found funny problem\situatuation. When you try to create dockerfile auto-generated by VS, generated Dockerfile placed in main project, not in root(.sln) folder, where exists .dockerignore.

I have next folder structure of my project:

<DIR>          .
<DIR>          ..
            82 .dockerignore
         6 305 .gitignore
<DIR>          MyProject.API
<DIR>          MyProject.API.Client
<DIR>          MyProject.Model
<DIR>          MyProject.Repository
<DIR>          MyProject.Repository.Settings
         6 567 MyProject.sln
         4 899 README.md
<DIR>          Tests.MyProject.Repository
<DIR>          Tests.Model
<DIR>          Tests.MongoContext.Infrastructure
<DIR>          Tests.MongoQuery
<DIR>          Tests.OdataFilters

Main project is MyProject.API.csproj (web api) in MyProject.API.

Auto-generated dockerfile from VS has next structure:

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

#VS generate copy command explicitly for dependencies of main project (model, repository, settings, etc.)
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["MyProject.API/MyProject.API.csproj", "MyProject.API/"]
COPY ["MyProject.Model/MyProject.Model.csproj", "MyProject.Model/"]
COPY ["MyProject.Repository/MyProject.Repository.csproj", "MyProject.Repository/"]
COPY ["MyProject.Repository.Settings/MyProject.Repository.Settings.csproj", "MyProject.Repository.Settings/"]
RUN dotnet restore "MyProject.API/MyProject.API.csproj"
COPY . .
WORKDIR "/src/MyProject.API"
RUN dotnet build "MyProject.API.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "MyProject.API.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyProject.API.dll"]

When I try build my image according to insturction from Docker, I have problem:

Linux container type:

Step 7/20 : COPY ["MyProject.API/MyProject.API.csproj", "MyProject.API/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder799586484/MyProject.API/MyProject.API.csproj: no such file or directory

Windows container type:

Step 7/20 : COPY ["MyProject.API/MyProject.API.csproj", "MyProject.API/"]
COPY failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder753862033\MyProject.API\MyProject.API.csproj: The system cannot find the path specified.

According to this answer I move my Dockerfile to the root folder (where exists .sln and .dockerignore files) and my problem was resolved.

Yaroslav
  • 504
  • 6
  • 13
1

There's a problem with the directory structure.

  1. Move your dockerfile to bin/Release/PublishOutput (after running VS publish > filesystem)
  2. move all the files into a site folder
  3. run docker build

https://forums.docker.com/t/copy-failed-trying-to-install-plain-asp-net-mvc-app-to-a-container/57217/3

I'm not sure how to get it to work automatically in VS yet.

AlignedDev
  • 8,102
  • 9
  • 56
  • 91
1

If you have this issue, especialy when you used visual studio, I am 98% sure that it is caused by missing exception in .dockerignore file. You need to add your file/directory to exceptions in .dockerignore

g0rski
  • 49
  • 6
1

This is probably being caused by the .dockerignore file next to your DockerFile, ignoring everything but /obj/Docker/:

*
!obj\Docker\publish\*
!obj\Docker\empty\

Update the .dockerignore to:

Dockerfile
[b|B]in
[O|o]bj
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
0

For vs2017

docker build -t sampleapplication . -f sampleapplication/dockerfile

normal build fails because it is unable to find the exact path of the location of the docker file .so that you can observe the dockerfile.yml COPY command

["sampleapplication/sampleapplication.csproj","sampleapplication/"]

and we also have a simple trick those who use the vs .the docker file builds by changing the copy command in the docked file

["./sampleapplication.csproj","sampleapplication/"]

RUN dotnet restore "./sampleapplication.csproj"