Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: COPY failed: CreateFile, looking for file in strange location

Trying to follow the tutorial found here, but running into problems.

I run the following command from my project dir:

docker build -t my.solution .

I get the following:

Sending build context to Docker daemon  111.6kB
Step 1/17 : FROM microsoft/aspnetcore:2.0-nanoserver-1709 AS base
 ---> ccfb41c8f5b5
Step 2/17 : WORKDIR /app
 ---> Using cache
 ---> e29a68e16001
Step 3/17 : EXPOSE 80
 ---> Using cache
 ---> 976388139964
Step 4/17 : FROM microsoft/aspnetcore-build:2.0-nanoserver-1709 AS build
 ---> d7ab4e860769
Step 5/17 : WORKDIR /src
 ---> Using cache
 ---> 4ab01220723e
Step 6/17 : COPY my.solution.sln ./
COPY failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder564035917\my.solution.sln: The system cannot find the file specified.

I don't know why it's trying to find the file in the location it's looking for it. Can anyone help me? Is there a config setting I need to make? My Docker file looks like this:

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

FROM microsoft/aspnetcore-build:2.0-nanoserver-1709 AS build
WORKDIR /src
COPY my.solution.sln ./
COPY my.solution/my.solution.csproj my.solution/
RUN dotnet restore -nowarn:msb3202,nu1503
COPY . .
WORKDIR /src/my.solution
RUN dotnet build -c Release -o /app

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

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

UPDATE

Per @AlexGera's answer, I tried changing my docker file to:

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

FROM microsoft/aspnetcore-build:2.0-nanoserver-1709 AS build
WORKDIR /src
VOLUME C:/tmp
COPY my.solution.sln c:/tmp/
COPY my.solution/my.solution.csproj my.solution/
RUN dotnet restore -nowarn:msb3202,nu1503
COPY . .
WORKDIR /src/my.solution
RUN dotnet build -c Release -o /app

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

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

but the error message doesn't change significantly:

docker build -t my.solution .
Sending build context to Docker daemon  111.6kB
Step 1/18 : FROM microsoft/aspnetcore:2.0-nanoserver-1709 AS base
 ---> ccfb41c8f5b5
Step 2/18 : WORKDIR /app
 ---> Using cache
 ---> e29a68e16001
Step 3/18 : EXPOSE 80
 ---> Using cache
 ---> 976388139964
Step 4/18 : FROM microsoft/aspnetcore-build:2.0-nanoserver-1709 AS build
 ---> d7ab4e860769
Step 5/18 : WORKDIR /src
Removing intermediate container 31e30e2346aa
 ---> 61c7df20f3c4
Step 6/18 : VOLUME C:/tmp
 ---> Running in fada6c728151
Removing intermediate container fada6c728151
 ---> 7a650440cc1f
Step 7/18 : COPY my.solution.sln c:/tmp/
COPY failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder832533802\my.solution.sln: The system cannot find the file specified.
like image 879
Jeremy Holovacs Avatar asked Mar 27 '18 12:03

Jeremy Holovacs


3 Answers

This was probably caused by the .dockerignore file next to you DockerFile, ignoring everything but /obj/*. Once you copied it to another folder you didn't copy the .dockerignore file, so nothing was excluded and it worked.

like image 157
Avner Levi Avatar answered Oct 02 '22 09:10

Avner Levi


Seems to me the standard Dockerfile that comes with a new solution is bugged :/

I moved the Dockerfile up to the solution folder, from PowerShell:

mv Dockerfile ../Dockerfile

Running the docker build command from there did the trick for me...

like image 32
EGeuens Avatar answered Nov 10 '22 23:11

EGeuens


The COPY command will copy the file from the build context, or a previous build stage if you specify the stage. With your build command:

docker build -t my.solution .

The context is . which is first sent to the docker engine which places that in a temporary location just for the build.

Therefore with your copy command:

Step 6/17 : COPY my.solution.sln ./

The file my.solution.sln needs to exist in the folder where the build command was run.

For the destination, the file will be copied to the working directory inside the container, or /src in your example.

like image 5
BMitch Avatar answered Nov 11 '22 01:11

BMitch