I am new with docker, trying to create my first docker image/container with .net core console application in Windows 10, following the article https://www.c-sharpcorner.com/article/getting-started-with-docker-for-windows-containerize-a-c-sharp-console-app/
I am getting the error message when building image:
COPY /bin/Debug/netcoreapp2.0/publish/ . COPY failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder989987487\bin
The content of my Dockerfile:
FROM microsoft/dotnet:2.0.4-runtime-nanoserver-1709 AS base
WORKDIR /app
COPY /bin/Debug/netcoreapp2.0/publish/ .
ENTRYPOINT ["dotnet", "ConsoleApp1.dll"]
C:\DotNetCore\ConsoleApp1\ConsoleApp1 is the root of my folder,
where I palced above Dockerfile.
C:\DotNetCore\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp2.1\publish
is the folder where content is get published by dotnet publish
command.
Command used to create the image:
docker build -t alphaimage .
You can try this, by removing the first / in the source directory of COPY:
FROM microsoft/dotnet:2.0.4-runtime-nanoserver-1709 AS base
WORKDIR /app
COPY bin/Debug/netcoreapp2.1/publish/ /app
ENTRYPOINT ["dotnet", "ConsoleApp1.dll"]
You are publishing to a folder that has netcoreapp2.1 in its name and the dockerfile is looking for a folder with netcoreapp2.0 in its name.
EITHER:
Change your csproj to use netcoreapp2.0:
<TargetFramework>netcoreapp2.0</TargetFramework>
OR
Update your COPY statement to use netcoreapp2.1
COPY /bin/Debug/netcoreapp2.1/publish/ .
Related
I've created a simple .NET Core 3.0 web API. In the project directory, I have a Dockerfile that looks like this:
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env
WORKDIR /app
# copy over csproj and restore nuget packages
COPY DockerWebApiSandbox.csproj ./
RUN dotnet restore
# copy everything else over into the same directory as the last copy step
# and run the publish step to build and gather output
COPY . ./
RUN dotnet publish -c Release -o output
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DockerWebApiSandbox.dll"]
When running docker build -t dockerwebapisandbox . from the working directory of my project, I see a failure on step 9 of 10 (third COPY command):
COPY failed: stat
/var/lib/docker/overlay2/f6f3391827aef74f1dab5716635a9119ae250ae94a216bbc0bc7b47c4030d60a/merged/app/out:
no such file or directory
When searching what the community was saying about this error, I found a suggestion here. The suggestion mentions screening into the VM, but this command fails, given that the com.docker.driver.amd64-linux/ directory does not exist where it's being expected. The screen command suggested looks like this: $ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
Other than trying the suggestion from the link above, I've tried uninstalling Docker and Docker Desktop altogether, in addition to the "Factory Reset" option provided in Docker Desktop.
FWIW, I am running MacOS Mojave. TIA for anyone who has suggestions.
I have faced the same error in Node. I was resolve using
COPY . .
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 just started a new solution with a .NET Core Project (2.1) using visual studio 15.8.8. It can run and debug it by setting the docker compose file as a startup project. It works!
Logically, I should be able to build the docker image with a simple commandline statement. However, it complains that the csproj cannot be found. This is strange. The file exist and as I told, I can run it from visual studio. I tried it from one directory up and the directory that has the dockerfile. Same problem.
How can I solve this? The only thing I want is simply build my image and then run it by just using docker commands.
Dockerfile
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["TryNewDocker2/TryNewDocker2.csproj", "TryNewDocker2/"]
RUN dotnet restore "TryNewDocker2/TryNewDocker2.csproj"
COPY . .
WORKDIR "/src/TryNewDocker2"
RUN dotnet build "TryNewDocker2.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "TryNewDocker2.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TryNewDocker2.dll"]
Het is the compose file:
version: '3.4'
services:
trynewdocker2:
image: ${DOCKER_REGISTRY}trynewdocker2
build:
context: .
dockerfile: TryNewDocker2/Dockerfile
Logically, I want "docker-compose up" to keep working when fixing this problem.
This is caused by the wrong root folder for the file path in dockerfile.
For launching from Docker, its root folder is C:\Users\...\repos\TryNewDocker2, but while running from command, its root fodler is C:\Users\...\repos\TryNewDocker2\TryNewDocker2, so the path for TryNewDocker2.csproj has changed from TryNewDocker2/TryNewDocker2.csproj to TryNewDocker2.csproj
Try dockerfile below:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 59162
EXPOSE 44342
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["TryNewDocker2.csproj", "TryNewDocker2/"]
RUN dotnet restore "TryNewDocker2/TryNewDocker2.csproj"
COPY . ./TryNewDocker2/
WORKDIR "/src/TryNewDocker2"
RUN dotnet build "TryNewDocker2.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "TryNewDocker2.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TryNewDocker2.dll"]
Update
For working in both Docker and command, do not change your dockerfile, and from path below to run your command with specifying the dockerfile path.
C:\Users\...\repos\TryNewDocker2>docker build -t gogo -f TryNewDocker2/Dockerfile .
For those of you who end up here years later like I did, I'll share my experience.
My problem was caused by the auto-generated Dockerfile that came from Visual Studio's "add > Docker Support..." was on the same level as my .csproj file.
The specific line causing me trouble was COPY ["MyApp/MyApp.csproj", "MyApp/"] which should have been just COPY ["MyApp.csproj", "MyApp/"]. Removing the extra MyApp/ in front of the .csproj got the build working fine.
Special thanks to Edward in the answer above for pointing me in the right direction.
Following the instructions on Docker's page I created a very simple Dockerfile that looks like this:
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "dockertest.dll"]
This is literally a copy of the sample on Docker's site just changed the application name.
I used Visual Studio for Mac to create a very simple ASP.Net application (actually, just the default app with a tiny HTML file added in).
When I first ran docker build -t dockertest . the line with dotnet publish failed. I then ran the dotnet publish manually and got past that.
It now fails on the copy:
Step 9/10 : COPY --from=build-env /app/out .
COPY failed: stat /var/lib/docker/overlay2/1484306cebf1def83638270757e70a8cf874fb5a167f39e5bfaae92a47cc071c/merged/app/out: no such file or directory
What's going on?
So did you run dotnet publish inside the container or on the host machine? The Docker file is trying to run those commands inside the container, so running those on the host will not fix the issue.
Have you tried to right click your project and "Add Docker Support" to your app in VS for Mac? It should generate a docker file and then you can run/debug your app inside the container from within VS.
I just got a MacBook Pro and am trying to run a dotnet core web api project I created on my Windows PC. I also am learning how to use Docker and am trying to integrate it into my project.
When I right click on my API project and hit Add > Docker Support, a docker-compose project and corresponding .yml file are generated and a Dockerfile is added to my Api project.
This is what the .yml file looks like:
version: '3.4'
services:
api:
image: api
build:
context: .
dockerfile: Api/Dockerfile
And here is the Dockerfile that is generated:
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY AdamWebsiteApi.sln ./
COPY Api/Api.csproj Api/
RUN dotnet restore -nowarn:msb3202,nu1503
COPY . .
WORKDIR /src/Api
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", "Api.dll"]
When I run the solution, using the docker-compose project as the startup, I get the following error:
Cannot start service api: Mounts denied:
The path /usr/local/share/dotnet/sdk/NuGetFallbackFolder
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.
Any idea what I need to do to get this working? It might be really simple and obvious but I am very new to Docker and Macs so I'm not sure what I'm doing.
Add the folder /usr/local/share/dotnet/sdk/NuGetFallbackFolder to the File Sharing list in Docker Preferences. It will work.