Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vs 2017 COPY failed: Docker File, CreateFile The system cannot find the file specified

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"]
like image 467
user3449299 Avatar asked Apr 12 '18 18:04

user3449299


1 Answers

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.

like image 165
Yaroslav Avatar answered Oct 13 '22 18:10

Yaroslav