docker - Copy bin directory , folder not found - docker

I have a dockerfile for my .net 6 project that just has the following:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
EXPOSE 8081
COPY bin/Release/net6/ App/
WORKDIR /App
ENTRYPOINT ["dotnet", "IdentityManager.dll"]
but when i try to build this, i get an error that the 'bin/Release/net6' folder isn't found. See the attached image to see my build command, and the file explorer showing that the folder does indeed exist. Is there something going on here that i'm not seeing? Thanks!

Related

Docker - cannot build simple dotnet webapi container: COPY failed: stat /var/lib/docker/overlay2 error

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

Docker compose build copy failed

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.

Can not copy files properly to docker image

Hello i am trying to recreate inside a docker image my host folder that contains:
Publish (folder containing a .NET app )
dockerfile
conf.json
dockerfile
FROM microsoft/aspnetcore
WORKDIR /app
ADD . /app
ENTRYPOINT ["dotnet","/publish/Bench.dll"]
EXPOSE 8300
When i am trying to see what it created using docker exec -it <id> bash it just takes all the content of publish and throws it inside app without copying conf.json.
I have also tried with
COPY . /app,
COPY /publish /app+COPY conf.json /app to no avail.
Whatever i am trying it won't copy the folder as-is and it wont put the json file beside it.
What am i doing wrong?
So I tested this out. I had the publish folder dockerfile and conf.json in the same directory where I build the image from. That is the key. Here I am using nginx as my base image. The following is the command I used to build the nginx image
docker build -t test/nginx .
and the dockerfile is as below. So I create the app directory by using the RUN command. You will have to use the similar command in .net to create that directory if it doesn't exist. Also pay attention to the docker build logs. It will tell you things that are important. Also you could add an ls command in the dockerfile to list the files in the folder /app if you want to.
FROM nginx
RUN mkdir /app
WORKDIR /app
ADD . /app
After I create a container from the image I built, i can navigate to /app folder and view my
Dockerfile, config.json and publish folder in there. Hope this helps
Let me know if you have any questions

Docker - Getting error while trying to build image

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

Unable to find image 'xxxx' locally

Basically I created an asp.net mvc project. I added a Dockerfile in the project folder.
FROM microsoft/aspnet:1.0.0-rc1-update1
ADD . /app
WORKDIR /app/approot
EXPOSE 5004
ENTRYPOINT ["./web"]
Now I open Docker Quickstart Terminal on my Windows desktop. Running the command
docker build -t hellodocker:0.1.0 .
See the result
However I can't find the image when I run it.
So what is wrong?
EDIT
Thanks for the comment, I correct the typo. But there is an another error.
EDIT-1
If I change the ENTRYPOINT as ENTRYPOINT ["dnx", "-p", "project.json", "web"]
Then I get another error:
Unable to reslolve project from /app/approot
EDIT-2
The context in the directory is as:
Your project is being added to the image as /app. So, in the container, the project.json lives at /app/project.json. But your WORKDIR is set to /app/approot.
This effectively makes your ENTRYPOINT looking for project.json at /app/approot, which it does not exist. You'll either need to change WORKDIR to /app or COPY . /app/approot.

Resources