Docker Copy Command fails - docker

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

Related

MSBUILD : error MSB1009: Project file does not exist when building docker file for an ASP.NET Core API application

I am trying to build a docker image for an ASP.NET Core 3.1 application and I fail to restore the packages. My solution has multiple projects and after copying all the project files, I am trying to create a layer which contains restored dependencies only.
The docker file
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["ExampleApi/ExampleApi.csproj", "ExampleApi/ExampleApi/"]
COPY ["Common.Web/Common.Web.csproj", "ExampleApi/Common.Web/"]
COPY ["Example.Data/Example.Data.csproj", "ExampleApi/Example.Data/"]
COPY ["Example.Services/Example.Services.csproj", "ExampleApi/Example.Services/"]
RUN mkdir /tmp/build/
COPY . /tmp/build
RUN find /tmp/build -name *.csproj
RUN dotnet restore "ExampleApi/ExampleApi.csproj" --verbosity detailed
COPY . .
WORKDIR "/src/ExampleApi/ExampleApi"
RUN dotnet build "ExampleApi.csproj" -c Release -o /app --no-restore
FROM build AS publish
RUN dotnet publish "ExampleApi.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ExampleApi.dll"]
Docker build
I am running without cache to be able to output all the csproj files within the container for each run (otherwise it gets cached and the files are not longer displayed).
docker build --no-cache -f ExampleApi/Dockerfile .
Sending build context to Docker daemon 116.4MB
Step 1/22 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
---> a843e0fbe833
Step 2/22 : WORKDIR /app
---> Running in e33e9c821c0b
Removing intermediate container e33e9c821c0b
---> eec973a226e0
Step 3/22 : EXPOSE 80
---> Running in 8e813a3a8b85
Removing intermediate container 8e813a3a8b85
---> c8d95a3a1de4
Step 4/22 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
---> cef7866e800b
Step 5/22 : WORKDIR /src
---> Running in f56bf9402ed1
Removing intermediate container f56bf9402ed1
---> 55694332db0e
Step 6/22 : COPY ["ExampleApi/ExampleApi.csproj", "ExampleApi/ExampleApi/"]
---> 4beb2e169ec7
Step 7/22 : COPY ["Common.Web/Common.Web.csproj", "ExampleApi/Common.Web/"]
---> ed7a9c81e8f7
Step 8/22 : COPY ["Example.Data/Example.Data.csproj", "ExampleApi/Example.Data/"]
---> aaca52c111b4
Step 9/22 : COPY ["Example.Services/Example.Services.csproj", "ExampleApi/Example.Services/"]
---> efb15c17a096
Step 10/22 : RUN mkdir /tmp/build/
---> Running in 7da9eae324ca
Removing intermediate container 7da9eae324ca
---> b06126b19a7f
Step 11/22 : COPY . /tmp/build
---> 04598eaab98c
Step 12/22 : RUN find /tmp/build -name *.csproj
---> Running in 2fd26dba963d
/tmp/build/ExampleApi/ExampleApi.csproj
/tmp/build/Example.Data/Example.Data.csproj
/tmp/build/Common.Web/Common.Web.csproj
/tmp/build/Example.Sql/Example.!Sql.csproj
/tmp/build/Example.Services/Example.Services.csproj
/tmp/build/Example.Services.Tests/Example.Services.Tests.csproj
/tmp/build/Example.IdentityServer.Infrastructure/Example.IdentityServer.Infrastructure.csproj
/tmp/build/Example.IdentityServer/Example.IdentityServer.csproj
/tmp/build/Example.Data.Tests/Example.Data.Tests.csproj
/tmp/build/ExampleIntegrationApi/ExampleIntegrationApi.csproj
Removing intermediate container 2fd26dba963d
---> 78eadf796305
Step 13/22 : RUN dotnet restore "ExampleApi/ExampleApi.csproj" --verbosity detailed
---> Running in 5dc9b5bbd04e
MSBUILD : error MSB1009: Project file does not exist.
Switch: ExampleApi/ExampleApi.csproj
The command '/bin/sh -c dotnet restore "ExampleApi/ExampleApi.csproj" --verbosity detailed' returned a non-zero code: 1
find indicates that ExampleApi/ExampleApi.csproj is there, yet the dotnet restore complains about not finding it.

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

.NET Core web app won't run in Docker container

I have a vanilla .NET Core 2 web app that I setup in JetBrains Rider and I immediately started working on a Docker environment for it. I followed this guide to get started:
https://docs.docker.com/engine/examples/dotnetcore/
I altered it slightly to come up with this:
FROM microsoft/dotnet:latest AS packager
RUN mkdir -p /opt/build
WORKDIR /opt/build
# Copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore
# Copy everything else and build
COPY . .
RUN dotnet publish -c Release -o bin
# --
# Build runtime image
FROM microsoft/dotnet:runtime AS runtime
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY --from=packager /opt/build/bin/. .
ENTRYPOINT ["dotnet", "/opt/app/aspnetapp.dll"]
The image builds and when I go to run the container I get the following output:
dan#mycomputer ~/Desktop/coreapi (master)
$ docker build -t myapp .
Sending build context to Docker daemon 25.09kB
Step 1/12 : FROM microsoft/dotnet:latest AS packager
---> e1a56dca783e
Step 2/12 : RUN mkdir -p /opt/build
---> Using cache
---> 95f9c936d0d1
Step 3/12 : WORKDIR /opt/build
---> Using cache
---> 64f26c356fd7
Step 4/12 : COPY *.csproj .
---> Using cache
---> 38a2fb7ca6bb
Step 5/12 : RUN dotnet restore
---> Using cache
---> 70dbc44d98ae
Step 6/12 : COPY . .
---> Using cache
---> b1019d53a861
Step 7/12 : RUN dotnet publish -c Release -o bin
---> Using cache
---> 8e112606633a
Step 8/12 : FROM microsoft/dotnet:runtime AS runtime
---> cc240a7fd027
Step 9/12 : RUN mkdir -p /opt/app
---> Using cache
---> 954f494febc4
Step 10/12 : WORKDIR /opt/app
---> Using cache
---> b74be941e7dc
Step 11/12 : COPY --from=packager /opt/build/bin/. .
---> Using cache
---> 4c229192d99b
Step 12/12 : ENTRYPOINT ["dotnet", "/opt/app/aspnetapp.dll"]
---> Using cache
---> fb6ef4015fba
Successfully built fb6ef4015fba
Successfully tagged myapp:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
dan#mycomputer ~/Desktop/coreapi (master)
$ docker run -p 5001:5001 myapp:latest
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
The app doesn't run and I get a message that says I need to install the SDK. What's up with that? Shouldn't the runtime Docker image have everything neede to run the app?
I was able to find the solution by modifying the ENTRYPOINT to run tail -f /dev/null. From there, I entered the container and saw that the name of the binary adjusts based on your project name which the Docker documentation didn't make clear to me.
I also updated my base images and this solved my problem. Here is my latest Dockerfile below:
FROM microsoft/dotnet:2.1-sdk AS packager
RUN mkdir -p /opt/build
WORKDIR /opt/build
# Copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore
# Copy everything else and build
COPY . .
RUN dotnet publish -c Release -o bin
# --
# Build runtime image
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY --from=packager /opt/build/bin/. .
EXPOSE 80
ENTRYPOINT ["dotnet", "/opt/app/coreapi.dll"]

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

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