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

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.

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...

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.

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.

Before copying add a volume in your image to copy where to.
Something like this:
VOLUME C:/Users/mysolution
COPY my.solution.sln C:/Users/mysolution
Try not to use dots for directory names.

I found that same situation in a VS2017 Solution where the build is started by docker compose and yml files one directory above the project.
If you want to build by docker build with the docker file directly, you need to move the docker file one level above the context

Use the \\
FROM microsoft\\aspnetcore-build:2.0-nanoserver-1709 AS build
see the below example
FROM microsoft/aspnetcore:2
WORKDIR /app
EXPOSE 80
COPY bin\\Debug\\netcoreapp2.0 .
ENTRYPOINT ["dotnet","DOCKER-API.dll"]

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

Perfect suits for who uses visual studio :
run this command :
docker build -t . your_application_name/Dockerfile
Dockerfile Copy path :
["your_application_name/your_application_name.csproj","your_application_name/"]
we run the build command docker build command it is unable to find the dockerfile in the project path location.

Visual Studio creates the Docker file at Project level, however, the Dockerfile is tailored to be run from an upper level (Solution level).
The easiest way to fix this problem is to go one level up (Solution folder), and specify the project folder:
docker build --tag tagone -f Project/Dockerfile .

Related

How to build Docker for VS 2019 solution?

I have a VS 2019 Solution with 2 projects: P1 (Standard lib) & P2 (ASP.NET Core exe).
P2 contains a Dockerfile.
I have copied the Docker file to up folder, tried to build the docker running the cmd :
>docker build -f Dockerfile ..
Sending build context to Docker daemon 3.056GB
Step 1/18 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
---> 5d7a95ed1660
Step 2/18 : WORKDIR /app
---> Using cache
---> 6e8271ae3df9
Step 3/18 : EXPOSE 80
---> Using cache
---> e45066aa184b
Step 4/18 : EXPOSE 443
---> Using cache
---> 0bbce5ed4c30
Step 5/18 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
---> 925a86b607a3
Step 6/18 : WORKDIR /src
---> Using cache
---> e4af901c8e34
Step 7/18 : COPY ["PropMan/PropMan.csproj", "PropMan/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder808977273/PropMan/PropMan.csproj: no such file or directory
How to fix it?
The directory structure
-Solution dir
--ChartJs.Blazor project
---ChartJs.Blazor.csproj
---ChartJs.Blazor files
--PropMan project
---PropMan.csproj
---PropMan files
---Dockerfie (it was created here but later I moved it to solution folder)
-Dockerfie
The Dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["PropMan/PropMan.csproj", "PropMan/"]
COPY ["ChartJs.Blazor/ChartJs.Blazor.csproj", "ChartJs.Blazor/"]
RUN dotnet restore "PropMan/PropMan.csproj"
COPY . .
WORKDIR "/src/PropMan"
RUN dotnet build "PropMan.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PropMan.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PropMan.dll"]
I need to go to the solution folder and run
docker build -f PropMan/Dockerfile .
The Dockefile is in project folder.

dotnet restore fails from Docker container

I have researched this for the past couple days and none of the research I've found has helped me solve this issue, including restarting Docker, restarting Docker service, restarting Visual Studio, deleting Nuget, adjusting proxy settings, adjusting Nuget.config etc etc.
Ultimately the error message I get is Unable to load the service index for source https://api.nuget.org/v3/index.json. but please bear with me I'm giving exect steps to reproduce this error.
When I create an ASP.NET Core Web Application in Visual Studio 2019, then Add Docker support to the project (Right click project, choose Add -> Docker Support...), a Dockerfile is created which looks like this:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["WebApplication3/WebApplication3.csproj", "WebApplication3/"]
RUN dotnet restore "WebApplication3/WebApplication3.csproj"
COPY . .
WORKDIR "/src/WebApplication3"
RUN dotnet build "WebApplication3.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication3.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication3.dll"]
When I build the docker image (Right click dockerfile, choose Build Docker Image), it builds fine and I get:
Starting up container(s)...
docker build -f "C:\Users\TheUser\source\repos\WebApplication3\WebApplication3\Dockerfile" --force-rm -t webapplication3:dev --target base --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=WebApplication3" "C:\Users\TheUser\source\repos\WebApplication3"
Sending build context to Docker daemon 4.396MB
Step 1/6 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
---> dc28376d4369
Step 2/6 : WORKDIR /app
---> Using cache
---> d0cbefb504d1
Step 3/6 : EXPOSE 80
---> Using cache
---> 865f960359d6
Step 4/6 : EXPOSE 443
---> Using cache
---> 4d040d5c8a4c
Step 5/6 : LABEL com.microsoft.created-by=visual-studio
---> Using cache
---> 4223be37abec
Step 6/6 : LABEL com.microsoft.visual-studio.project-name=WebApplication3
---> Running in d1ced38ba0fa
Removing intermediate container d1ced38ba0fa
---> fb400230edf4
Successfully built fb400230edf4
Successfully tagged webapplication3:dev
docker run -dt -v "C:\Users\TheUser\onecoremsvsmon\16.4.0067.0:C:\remote_debugger:ro" -v "C:\Users\TheUser\source\repos\WebApplication3\WebApplication3:C:\app" -v "C:\Users\TheUser\source\repos\WebApplication3:C:\src" -v "C:\Users\TheUser\AppData\Roaming\Microsoft\UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro" -v "C:\Users\TheUser\AppData\Roaming\ASP.NET\Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro" -v "C:\Users\TheUser\.nuget\packages\:c:\.nuget\fallbackpackages2" -v "C:\Program Files\dotnet\sdk\NuGetFallbackFolder:c:\.nuget\fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "NUGET_PACKAGES=c:\.nuget\fallbackpackages2" -e "NUGET_FALLBACK_PACKAGES=c:\.nuget\fallbackpackages;c:\.nuget\fallbackpackages2" -P --name WebApplication3 --entrypoint C:\remote_debugger\x64\msvsmon.exe webapplication3:dev /noauth /anyuser /silent /nostatus /noclrwarn /nosecuritywarn /nofirewallwarn /nowowwarn /fallbackloadremotemanagedpdbs /timeout:2147483646 /LogDebuggeeOutputToStdOut
eba5dec02ed7a80158340d6f8d6af504b86edf7cd6944eb1d4ce71f7847fabb5
Container started successfully.
========== Finished ==========
However if I add a .Net Core Class Library to the solution, add that class library as a project reference to the Web Application and Add Docker Support again, I get a new Dockerfile that looks like this:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["WebApplication3/WebApplication3.csproj", "WebApplication3/"]
COPY ["ClassLibrary1/ClassLibrary1.csproj", "ClassLibrary1/"]
RUN dotnet restore "WebApplication3/WebApplication3.csproj"
COPY . .
WORKDIR "/src/WebApplication3"
RUN dotnet build "WebApplication3.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication3.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication3.dll"]
And when I Build Docker Image again this time I get an error which looks like this:
1>------ Rebuild All started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
1>ClassLibrary1 -> C:\Users\TheUser\source\repos\WebApplication3\ClassLibrary1\bin\Debug\netcoreapp3.1\ClassLibrary1.dll
2>------ Rebuild All started: Project: WebApplication3, Configuration: Debug Any CPU ------
2>docker rm -f eba5dec02ed7a80158340d6f8d6af504b86edf7cd6944eb1d4ce71f7847fabb5
2>eba5dec02ed7a80158340d6f8d6af504b86edf7cd6944eb1d4ce71f7847fabb5
2>WebApplication3 -> C:\Users\TheUser\source\repos\WebApplication3\WebApplication3\bin\Debug\netcoreapp3.1\WebApplication3.dll
2>WebApplication3 -> C:\Users\TheUser\source\repos\WebApplication3\WebApplication3\bin\Debug\netcoreapp3.1\WebApplication3.Views.dll
2>Docker version 19.03.8, build afacb8b
2>docker build -f "c:\users\TheUser\source\repos\webapplication3\webapplication3\dockerfile" --force-rm -t webapplication3 --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=WebApplication3" "c:\users\TheUser\source\repos\webapplication3"
2>Sending build context to Docker daemon 4.4MB
2>
2>Step 1/20 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
2> ---> dc28376d4369
2>Step 2/20 : WORKDIR /app
2> ---> Using cache
2> ---> d0cbefb504d1
2>Step 3/20 : EXPOSE 80
2> ---> Using cache
2>Step 4/20 : EXPOSE 443
2> ---> 865f960359d6
2> ---> Using cache
2> ---> 4d040d5c8a4c
2>Step 5/20 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
2> ---> c67fa4d2a089
2>Step 6/20 : WORKDIR /src
2> ---> Using cache
2> ---> 14763e98238e
2>Step 7/20 : COPY ["WebApplication3/WebApplication3.csproj", "WebApplication3/"]
2> ---> ad0ded95d169
2>Step 8/20 : COPY ["ClassLibrary1/ClassLibrary1.csproj", "ClassLibrary1/"]
2> ---> 22667eda405c
2>Step 9/20 : RUN dotnet restore "WebApplication3/WebApplication3.csproj"
2> ---> Running in a3e6a184b4e9
2> Restore completed in 495.4 ms for C:\src\ClassLibrary1\ClassLibrary1.csproj.
2>C:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\src\WebApplication3\WebApplication3.csproj]
2>C:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5): error : No such host is known. [C:\src\WebApplication3\WebApplication3.csproj]
2>Removing intermediate container a3e6a184b4e9
2>The command 'cmd /S /C dotnet restore "WebApplication3/WebApplication3.csproj"' returned a non-zero code: 1
2>c:\users\TheUser\source\repos\webapplication3\webapplication3\dockerfile : error CTC1014: Docker command failed with exit code 1.
2>c:\users\TheUser\source\repos\webapplication3\webapplication3\dockerfile : error CTC1014: The command 'cmd /S /C dotnet restore "WebApplication3/WebApplication3.csproj"' returned a non-zero code: 1
2>Done building project "WebApplication3.csproj" -- FAILED.
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
Should be easy to reproduce. Why does it work without the class library reference then error when adding a reference? Do I need to update the Dockerfile with something extra? I have been going around in circles with this and none of the other posts on the subject have phrased it this way or given me any answers that work for me.
The actual error seems to be:
Unable to load the service index for source https://api.nuget.org/v3/index.json
Which means that nuget is failing to access the endpoint when it is trying to download the dependencies.
There are a number of solutions to this listed here
https://github.com/NuGet/Home/issues/2880
and also
Nuget connection attempt failed "Unable to load the service index for source"
Not able to reproduce it. This is my docker file.
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 ["WebApplication1.csproj", ""]
COPY ["../ClassLibrary1/ClassLibrary1.csproj", "../ClassLibrary1/"]
RUN dotnet restore "./WebApplication1.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Different line:
COPY ["../ClassLibrary1/ClassLibrary1.csproj", "../ClassLibrary1/"]
RUN dotnet restore "./WebApplication1.csproj"
I think your csproj and sln file are in different folder. When using visual studio make sure you select the option: Place solution and project file in the same folder
2nd Update to the answer:
With every project that you add/reference. Please add support for Docker.
This'll update the docker file.
Are you behind a proxy of some sort? Corporate or otherwise.
I was able to get around this issue by setting the http_proxy in my Dockerfile.
ARG HTTP_PROXY="http://username:password#proxy.example.com:8080"
Full Dockerfile example below:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
ARG HTTP_PROXY="http://username:password#proxy.example.com:8080"
USER administrator
RUN dotnet restore
# Copy everything else and build
COPY . ./
USER administrator
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "myapp.dll"]
If you can't access that nuget endpoint then I'd be curious about 2 things:
Maybe you don't mean to be at all
All of your dependencies live in a private repository (a different endpoint)
If both or either of 1 and 2 above are true and you have a NuGet.Config file managing your dependencies then try and remove any hard-coded Package References from your *.csproj file, then try your docker build again.
If you don't have a NuGet.Config and are referencing your project packages directly from your *.csproj file still I would recommend creating one and removing those references from the project file itself. If not for Docker purposes, then at least for the sake of good organization/separation of concerns.
One last thing, make sure that NuGet.Config file is at the same directory level as your Dockerfile. Dockerfiles will not "see anything" not at their same directory level (even if you have proper relative paths in your Dockerfile so it could theoretically see them if it worked that way).
I ran into a similar problem with dotnet restore causing the Unable to load the service index for source https://api.nuget.org/v3/index.json.
For me the solution was to set dns in the Docker Engine settings, as described in one of the answers in here: Docker container cannot resolve hosts

no such file or directory in COPY dockerfile

I have made the following dockerfile to contain my node js application, the problem is that an error appears when building the dockerfile:
Sending build context to Docker daemon 2.048kB
Step 1/7 : FROM node:10
---> 0d5ae56139bd
Step 2/7 : WORKDIR /usr/src/app
---> Using cache
---> 5bfc0405d8fa
Step 3/7 : COPY package.json ./
COPY failed: stat /var/lib/docker/tmp/docker-
builder803334317/package.json: no such file or directory
this is my dockerfile:
FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
i executed the command:
sudo docker build - < Dockerfile
into my root project folder.
My project folder is simple, like this:
-Project
-app.js
-Dockerfile
-package.json
-package-lock.json
-README.md
I am doing something wrong?
When you use the Dockerfile-on-stdin syntax
sudo docker build - < Dockerfile
the build sequence runs in a context that only has the Dockerfile, and no other files on disk.
The directory layout you show is pretty typical, and pointing docker build at that directory should work better
sudo docker build .
(This is the same rule as the "Dockerfiles can't access files in parent directories" rule, but instead of giving the current directory as the base directory to Docker, you're giving no directory at all, so it can't even access files in the current directory.)

Docker Copy Command fails

I am new to Docker , while running the Docker file
My Docker file
FROM microsoft/dotnet:2.2.0-preview1-aspnetcore-runtime AS base
WORKDIR /app
FROM microsoft/dotnet:2.2.100-preview1-sdk AS build
WORKDIR /DineshVisualStudio/Autofac-interceptor/AutofacModule/Autofac.interface.ConcactFactory
COPY Autofac.Interface.ConcatFactory.csproj project/
WORKDIR /Autofac-interceptor/project
RUN dotnet restore
COPY /Autofac.interface.Concactfactory .
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 ["Autofac.Interface.ConcatFactory.exe"]
When running docker build -t myappfactory . it's failing. I tried many combinations for the path in COPY command but without any luck.
I am using Visual Studio 2017 and had installed Docker Tools too
This is my folder structure
My folder structure with the code having docker file
when running docker build -t autofacinterface . I'm getting an Error saying:
failed to create file . System cannot find the file specified.
I am using Cmd to build the docker from my current working .csproj folder.
D:\DineshVisualStudio\Autofac-Interceptor\AutofacModule\Autofac.Interface.ConcatFactory>docker build -t autofacinterfaceconcatfactory .
Sending build context to Docker daemon 4.608kB
Step 1/15 : FROM microsoft/dotnet:2.2.0-preview1-aspnetcore-runtime AS base
---> 2df5940c47f7
Step 2/15 : WORKDIR /app
---> Using cache
---> f4d2190d9b44
Step 3/15 : FROM microsoft/dotnet:2.2.100-preview1-sdk AS build
---> af242cb10bf0
Step 4/15 : WORKDIR /DineshVisualStudio/Autofac-
interceptor/AutofacModule/Autofac.interface.ConcactFactory
---> Using cache
---> dbf15787395b
Step 5/15 : COPY /Autofac.Interface.ConcatFactory.csproj project/
COPY failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-
builder138146052\COPY: The system cannot find the file specified.
after #Mike suggestion I am getting this issue:
D:\DineshVisualStudio\Autofac-Interceptor\AutofacModule\Autofac.Interface.ConcatFactory>docker build -t myappfact .
Step 6/15 : WORKDIR /Autofac-interceptor/project
Step 7/15 : RUN dotnet restore
---> Running in 9e91df3e68a3
MSBUILD : error MSB1003: Specify a project or solution file. The current
working directory does not contain a project or solution file.
The command 'cmd /S /C dotnet restore' returned a non-zero code: 1
I don't think you need the leading / in COPY /Autofac.Interface.ConcatFactory.csproj. The source file(s) are relative to current working directory, and you've already called WORKDIR previously.
https://docs.docker.com/engine/reference/builder/#copy
Step 5/15 : COPY COPY
Do you have the word COPY twice in a row in your Dockerfile?
The command "COPY /Autofac.Interface.ConcatFactory.csproj project/" failed. I recommend you read more about the command COPY here. Use the command "COPY . ." if you run docker build from the folder "D:\DineshVisualStudio\Autofac- Interceptor\AutofacModule\Autofac.Interface.ConcatFactory".

Docker compose build error - Project file does not exist

I'm trying to create docker compose which run my ASP.NET Core app and mssql, but I'm getting an error during build.
Here's my docker compose file:
# Build Stage
FROM microsoft/aspnetcore-build:latest as build-env
WORKDIR /source
COPY . .
RUN dotnet restore ./Travelingowe.sln
RUN dotnet publish --output ${source:-obj/Docker/publish} --configuration Release
# Publish Stage
FROM microsoft/aspnetcore:latest
COPY --from=build-env ./obj/Docker/publish /app
WORKDIR /app
ENTRYPOINT ["dotnet", "Api.dll"]
when I run in CMD -> docker-compose up I'm getting:
Building api
Step 1/9 : FROM microsoft/aspnetcore-build:latest as build-env
---> d6273f7c44d4
Step 2/9 : WORKDIR /source
---> Using cache
---> 978f1c31e14a
Step 3/9 : COPY . .
---> Using cache
---> bcc750adcb99
Step 4/9 : RUN dotnet restore ./Travelingowe.sln
---> Running in 764199859de4
MSBUILD : error MSB1009: Project file does not exist.
Switch: ./Travelingowe.sln
ERROR: Service 'api' failed to build: The command '/bin/sh -c dotnet restore ./Travelingowe.sln' returned a non-zero code: 1
Do you have any ide what is wrong?
Thanks!
UPDATE:
My project files:
you have issues with your working directory try using absolute path instead of relative path in your working directory in docker file
TL;DR
Put your Dockerfile in your project root folder.
There are several question you need to think of:
Where is your Dockerfile?
How does docker-compose.yaml point to Dockerfile?
It seems like you put your Dockerfile in the other folder.
As document mentions:
Compose uses an alternate file to build with. A build path must also be specified.
When you use the Dockerfile on different folder with docker-compose.yaml you have to set up the context property.
As it set up, it will consider the Dockerfile's folder as project root folder. So when the command dotnet restore ./Travelingowe.sln executed, it shows you the error
You can manually test the command by running dotnet restore ./Travelingowe.sln in Dockerfile's folder. It should show the detail error message.

Resources