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.
Related
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
I am really curious to how to interpret and debug with the following error:-
C:\users\project>docker-compose build
Step 6/15 : COPY *.csproj ./
ERROR: Service 'invoiceservice' failed to build: COPY failed: no source files were specified
This is particular micro-service as i have few more such services.
docker file :-
FROM mcr.microsoft.com/dotnet/core/runtime:2.2 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY *.csproj ./
RUN dotnet restore -s https://api.nuget.org/v3/index.json -s https://www.myget.org/F/autoweb/api/v3/index.json
COPY . .
WORKDIR /src/src/InvoiceManagement/InvoiceService
RUN dotnet publish -c Release -o out
FROM build AS publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/out .
ENTRYPOINT ["dotnet", "InvoiceService.dll"]
Interesting part is when I build this from Visual Studio IDE, its being built fine but it does not build on CLI.
docker compose file:-
invoiceservice:
image: ${DOCKER_REGISTRY-}invoiceservice
build:
context: .
dockerfile: src/InvoiceManagement/InvoiceService/Dockerfile
I don't understand why CLI could not find the source location and copy where as VS works fine. Any clue???
It's likely an issue with your Docker context. Commands in Dockerfiles are relative to where the docker/docker-compose CLI tool is run, not relative to the Dockerfile location.
In other words, if you run the command from the solution root, then your csproj file is actually under ./src/InvoiceManagement/InvoiceService. As a result, *.csproj finds no files, because there's no project files literally in your solution root.
I tried replicating your problem and I was able to copy all the files successfully (instead of .csproj, I used .txt). The problem occurred when there was no txt file to copy. My COPY command failed with exactly the same message as yours.
Now, why is VS able to build the image successfully? That is because VS build the project first! When the project's build procedure is completed, a .csproj file is generated and that gets copied to the image.
To confirm the results, ls your current directory (when the build fails from command line) and see if there is any .csproj file in that directory.
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".
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 .
I am trying to build a .NET core MVC project in a Docker container via Jenkins. I have set up the pipeline to pull from git and build inside a Docker container, but I keep getting these errors when I try to build my solutions.
I got the Dockerfile from https://docs.docker.com/engine/examples/dotnetcore/#create-a-dockerfile-for-an-aspnet-core-application and changed it appropriately for my project. It is placed inside the project directory in the same folder as my .sln file. For some reason, it's failing. My file structure seems to be right, but the script cannot seem to find my project or the build tools inside the imported environment.
Error text (Jenkins)
[fundprofiles-docker_jenkins-B5GJFHQUL2XVSIUP7TPI255RMTFK5MJKMLIMBSXSXMQQJSZSEG5A] Running shell script
+ docker build -t e9f05c806e193d6c1920e5d5c23ed34350c4f491 -f Dockerfile .
Sending build context to Docker daemon 234.9MB
Step 1/9 : FROM microsoft/aspnetcore-build:2.0 AS build-env
---> 6105426f13e9
Step 2/9 : COPY *.sln ./
---> Using cache
---> 978a5d201ae0
Step 3/9 : RUN dotnet restore
---> Using cache
---> 2ac341942a6d
Step 4/9 : COPY . ./
---> 07c15ea85ca8
Step 5/9 : RUN dotnet publish -c Release -o out
---> Running in bf35842f7b24
Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
/myapp/myapp.csproj(582,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/2.1.4/Microsoft/VisualStudio/v15.0/WebApplications/Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
/myapp/myapp.csproj : warning NU1503: Skipping restore for project '/myapp/myapp.csproj'. The project file may be invalid or missing targets required for restore. [/myapp.sln]
/usr/share/dotnet/sdk/2.1.4/NuGet.targets(103,5): warning : Unable to find a project to restore! [/myapp.sln]
/myapp/myapp.csproj(582,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/2.1.4/Microsoft/VisualStudio/v15.0/WebApplications/Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
script returned exit code 1
Dockerfile:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /
# Copy csproj and restore as distinct layers
COPY *.sln ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /
COPY --from=build-env /out .
ENTRYPOINT ["dotnet", "myApp.dll"]
From the logs, it looks like you are building an ASP.NET MVC application, not an ASP.NET Core application, which is not supported by the dotnet cli.
Follow guides about dockerizing non-core ASP.NET applications (some guides call this a "legacy ASP.NET application") like https://learn.microsoft.com/en-us/aspnet/mvc/overview/deployment/docker-aspnetmvc