Net core project and I have many webapi, business layer and some other layers here. Below is the folder stucture.
Main Solution
businessLayer
data layer
Web API layer
3.1 MyDockerFile
Below is my docker file.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
COPY ["Enrichment.WebApi/Enrichment.WebApi.csproj", "Enrichment.WebApi/"]
COPY ["Enrichment.Facade/Enrichment.Facade.csproj", "Enrichment.Facade/"]
COPY ["Enrichment.Saga/Enrichment.Saga.csproj", "Enrichment.Saga/"]
COPY ["Enrichment.BusinessModel/Enrichment.BusinessModel.csproj", "Enrichment.BusinessModel/"]
RUN dotnet restore "Enrichment.WebApi/Enrichment.WebApi.csproj"
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
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", "Enrichment.WebApi.dll"]
When I run docker build -t enrichment.webapi . I get below output
Sending build context to Docker daemon 230.8MB
Step 1/16 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
---> 9a88f73dec65
Step 2/16 : WORKDIR /app
---> Using cache
---> 9b50f1fc6721
Step 3/16 : COPY ["Enrichment.WebApi/Enrichment.WebApi.csproj", "Enrichment.WebApi/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder437963979/Enrichment.WebApi/Enrichment.WebApi.csproj: no such file or directory
I am not able to understand why I am getting above error. Path looks like incorrect but I am not able to understand what would be the right path. can someone help me to understand any issue here. Any help would be appreciated. Thank you.
Step 9/16 : COPY *.csproj ./ COPY failed: no source files were specified
This is because of .dockerignore file that ignores the csproj. Notice the content of .dockerignore below and Anything other than obj/Docker/publish/* and obj/Docker/empty is ignored.
*
!obj/Docker/publish/*
!obj/Docker/empty/
Incude this in your dockerfile
# build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out ./
Related
I have made a asp.net core 2.0 web API.
Now I want to create a docker image for this API.
Here is my docker file content -
FROM microsoft/aspnetcore:2.0-nanoserver-1803 AS build-env
WORKDIR /app
FROM microsoft/aspnetcore-build:2.0-nanoserver-1803 AS base
WORKDIR /src
# 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 base AS final
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Microservice_Orders.dll"]
I am running the following command to create an image
docker build -t ms_orders .
But I am getting following error on execution.
******Step 11/12 : COPY --from=build-env /app/out . COPY failed: CreateFile \?\Volume{a3251a00-f8f4-4510-8db2-f495f33ce178}\app\out:
The system cannot find the file specified.******
I found a few things to be a bit strange in that dockerfile.
It looks like you have base and build-env mixed up, i.e. you're building into base, but then trying to copy what you built from build-env.
Also the path from dotnet publish doesn't match the path in COPY --from=build-env.
/src/out (I think) vs /app/out
I would try to change it to below. I have copied the dockerfile and commented where I've made changes.
FROM microsoft/aspnetcore:2.0-nanoserver-1803 AS base # name changed since this is your base
WORKDIR /app
EXPOSE 80 # You'll probably also need to expose the app on some port(s)
EXPOSE 443 # depending on if you want https or not, you can remove one of these lines
FROM microsoft/aspnetcore-build:2.0-nanoserver-1803 AS build-env # name changed since this is where you build
WORKDIR /src
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o /app/out # output path changed!
# Build runtime image
FROM base AS final
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Microservice_Orders.dll"]
Disclaimer: I haven't actually tried to build it, so there could be a few more issues.
My dotnet core 2.2 app have this structure (which is pretty standard):
- .sln
- DockerFile
- MyApp/
|- *.csproj
My DockerFile is this:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY ./MyApp/*.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyApp.dll"]
I always get this error:
Step 9/10 : COPY --from=build-env /app/out .
ERROR: Service 'myapp' failed to build: COPY failed: stat /var/lib/docker/overlay2/ed30d6e8a88b5d65bb14a5e972428135a78701c860f510d4dcc3e5c4947916d3/merged/app/out: no such file or directory
I looked online and could only find suggestions about resetting the data of Docker, which I tried without any kind of success.
I'm building using the command docker build . from the DockerFile repository.
Is there something missing from my DockerFile? Do you have any clue to help me figure this out?
I have similar dockerfile. but my output is /out
and also copy from /out
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY ./MyApp/*.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o /out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY --from=build-env /out .
ENTRYPOINT ["dotnet", "MyApp.dll"]
I have .sln file and Dockerfile at a different location on my local hard drive.
Till now I work on a source code where .sln file and Dockerfile are present at the same location.
I am facing difficulty to configure it correctly.
I have .sln file at the location CompanyCarsDocker\CompanyCarsDocker\CompanyCarsDocker.sln
And My Dockerfile is present inside CompanyCarsDocker\CompanyCarsDocker\CarApi\Dockerfile
-
Below is my Dockerfile
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 54411
FROM microsoft/aspnetcore-build:2.0 AS builder
WORKDIR /src
COPY . ./*.sln ./
ADD ./site /inetpub/wwwroot
COPY ./CarApi.csproj CarApi/
RUN dotnet restore
COPY . .
WORKDIR /src/CarApi
RUN dotnet build -c Release -o /app
FROM builder AS publish
RUN dotnet publish -c Release -o /app
FROM base AS production
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "CarApi.dll"]
I have added ADD ./site /inetpub/wwwroot for testing purpose. I am getting
ADD failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder782713904\site: The system cannot find the file specified.
Same error I am also Getting at COPY ./CarApi.csproj CarApi/
Please let me know if I configured something wrong in the Dockerfile.
You can use the -f flag of docker build to specify the path to the Dockerfile
Make sure you’re current working directory is the one which has the sln file and rest of the project. Run the command docker build -f <path to Dockerfile> .
your .sln file is two directories up so you should use
COPY ../../*.sln ./
instead of
COPY . ./*.sln ./
I am completely new to Docker. I am trying to learn how to dockerize .NET Core app based on tutorial.
Whatever I do, I can't dockerize it. I am always stuck on:
RUN dotnet publish -c Release -o out
within dockerfile.
Errors I get are:
C:\Program Files\dotnet\sdk\2.1.200\NuGet.targets(114,5): error : An
error occurred while sending the request. [C:\app\TokenGen.csproj]
C:\Program Files\dotnet\sdk\2.1.200\NuGet.targets(114,5): error :
The server name or address could not be resolved
[C:\app\TokenGen.csproj]
I noticed that he is pointing to
C:\app
even tho my sample project is on
H:\Bitbucket\dockertest\TokenGen
This is my full dockerfile:
FROM microsoft/aspnetcore-build:2.0 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/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
I am trying to make use of this Docker construct:
Optionally a name can be given to a new build stage by adding AS name
to the FROM instruction. The name can be used in subsequent FROM and
COPY --from= instructions to refer to the image built in
this stage.
But I get this message:
COPY failed: stat /var/lib/docker/tmp/docker-builder869050639/-–from=build-env:
no such file or directory
Is copying files from a previous stage supported on Docker for Windows 17.09.0-ce-win33 (13620)? This is the Dockerfile:
FROM microsoft/dotnet:2.0-sdk AS build-env
WORKDIR /app
COPY ./ ./
RUN dotnet build ProviderApi.csproj
RUN dotnet publish ProviderApi.csproj -c Release -r linux-x64 -o out
FROM microsoft/dotnet:2.0-runtime-deps
WORKDIR /app
COPY -–from=build-env /app/out/ ./
EXPOSE 80
ENTRYPOINT ["./ProviderApi"]
The problem was that the destination directory was not present in the docker image of the final build stage. Here is the working Dockerfile for future reference.
FROM microsoft/aspnetcore-build:2.0.3-stretch AS build-env
WORKDIR /app
COPY . ./
RUN dotnet build ProviderApi.csproj
RUN dotnet publish ProviderApi.csproj -c Release -r linux-x64 -o out
FROM microsoft/aspnetcore:2.0.3-stretch
RUN mkdir /app
COPY --from=build-env /app/out /app
ENV ASPNETCORE_URLS=http://+:5001
EXPOSE 5001
ENTRYPOINT ["/app/ProviderApi"]
have you tried with lowercase "as"? (seems like a long-shot, I see examples of both around)
FROM microsoft/dotnet:2.0-sdk as build-env
or the more basic
FROM microsoft/dotnet:2.0-sdk
COPY -–from=0 /app/out/ ./