When using docker, I get DirectoryNotFoundException in PhysicalFileProvider in blazor - docker

I created a blazor project using .netcore3.1.
I use PhysicalFileProvider in startup.cs.
I ran it with docker using config in docker.
The build was successful, but an exception occurred during execution.
The docker file is as follows:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["Web/Web.csproj", "Web/"]
RUN dotnet restore "Web/Web.csproj"
COPY . .
WORKDIR "/src/Web"
RUN dotnet build "Web.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Web.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Web.dll"]
This is a docker file automatically generated by Visual Studio.
Why can't the program find the directory?
Or, is there another way to find the directory?

Related

How to build dockerfile with multiple dependent assemblies to asp.net core webapi, as i am getting docker build error?

1. MY Docker file is below.
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["TestAPI/TestAPI.csproj", "TestAPI/"]
RUN dotnet restore "TestAPI/TestAPI.csproj"
COPY . .
WORKDIR "/src/TestAPI"
RUN dotnet build "TestAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "TestAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestAPI.dll"]
2. My solution structure is below.
Solution Structure
3.Folder structure
Folder structure
4.Error I am getting is below:
Docker build error

Running Sqlite in a docker container

I have a small application that I want to containerize in .Net5.0. It works well outside docker but if added RUN dotnet ef database update to my docker file, it gives a build error. I don't know if I placed it in a wrong place or it doesn't work that way.
Also will COPY --from=publish /app/publish/tomix.db . copy the new database file correctly?
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["API/API.csproj", "API/"]
RUN dotnet ef database update
RUN dotnet restore "API/API.csproj"
COPY . .
WORKDIR "/src/API"
RUN dotnet build "API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish/tomix.db .
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API.dll"]
UPDATE This is the error after running dotnet build -t tomix .
AFAIK, the dotnet ef tool is no longer part of the .NET SDK, and needs to be explicitly installed. I.e., before attempting to RUN dotnet ef database update you must RUN dotnet tool install dotnet-ef

Docker image doesnt work - probably wrong paths on build

I'm trying to move ASP.NET Core project to docker linux container, however I cannot build up a proper image. When I create default dockerfile (through VisualStudio Add -> DockerSupport) it's setting up paths for COPY to all of the projects. However when I run docker build -t . it pop's out error "no such file or directory". I've tried to stick with official docker documentation with moving asp.net core to docker containers and here is the code I ended with:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ./ ./
RUN dotnet restore "myproject.csproj"
COPY . .
WORKDIR "/src/myproject"
RUN dotnet build "myproject.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "myproject.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "myproject.dll"]
This is the command im using to build up an image:
docker build -t myapp -f myproject/Dockerfile .
I'm building it from the parent directory, because when I was using current working directory it wasn't finding all the .csproj files. When I run this image it doesn't work - I know there are wrong paths, however I have no idea where is the error in logic. Current error is "Program does not contain a static 'Main' method suitable for an entry point" and "A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/'. Failed to run as a self-contained app. If this should be a framework-dependent app, specify the appropriate framework in /app/myproject.runtimeconfig.json"
Try the following based off this documentation replace myproject with project name
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", “myproject.dll"]
Then build and run with the following commands:
docker build -t myproject .
docker run -d -p 8080:80 --name myapp myproject
You should not specify RUN dotnet build "myproject.csproj" -c Release -o /app with -o /app which will output in the same folder with build layer.
Try
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["myproject/*.csproj", "myproject/"]
RUN dotnet restore "myproject/myproject.csproj"
COPY . .
WORKDIR /src/myproject
RUN dotnet build "myproject.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "myproject.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "myproject.dll"]

How to map changes of .NET application from docker and rebuild?

I am currently developing a NET Application and I have to run bash scripts that:
1.Build the project
2.dotnet publish -c Release the project
3.copy the publish folder to a path for Dockerfile to take on.
Can this be done directly from the dockerfile?
What I am running now:
Bash-script
dotnet build ../${serverSrcFolder} &&
dotnet publish -c Release ../${serverSrcFolder} --output $(pwd)/${serverPublishDestFolder}
Dockerfile
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
COPY . /app
ENTRYPOINT [ "dotnet" , "./publish/Server.dll" ]
EXPOSE 9400
EXPOSE 6379
The publish folder stays near the dockerfile.
ParentFolder
Dockerfile
publish
The serverPublishDestFolder from the bash script above is this publish folder.
Can I somehow always map the publish folder whenever it changes from within the dockerfile?
You can do three steps above inside the Dockerfile
e.g.
ROM microsoft/dotnet:2.1.5-aspnetcore-runtime AS base
WORKDIR /app
ENV ASPNETCORE_URLS http://+:5000
EXPOSE 5000
FROM microsoft/dotnet:2.1.403-sdk AS build
WORKDIR /src
COPY src/WebApi/WebApi.csproj src/WebApi/
RUN dotnet restore src/WebApi/WebApi.csproj
COPY . .
WORKDIR /src/src/WebApi
RUN dotnet build WebApi.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish WebApi.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApi.dll"]
This Dockerfile can be easily generated by Visual Studio 2017

how to build docker image file and push Vsts

How to address this error when I push my code on VSTS platform. I am using Visual Studio 2017.
I am new to the concept of Docker ,Azure (VSTS).
FROM microsoft/aspnetcore:1.1 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:1.1 AS build
WORKDIR /src
COPY ["aspnet-core-dotnet-core/aspnet-core-dotnet-core.csproj", "aspnet-core-dotnet-core/"]
RUN dotnet restore "aspnet-core-dotnet-core/aspnet-core-dotnet-core.csproj"
COPY . .
WORKDIR "/src/aspnet-core-dotnet-core"
RUN dotnet build "aspnet-core-dotnet-core.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "aspnet-core-dotnet-core.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "aspnet-core-dotnet-core.dll"]
Based on the DockerFile and error message, it failed to copy aspnet-core-dotnet-core/aspnet-core-dotnet-core.csproj file.
You need to specify DockerFile's parent folder path as the build context (Uncheck Use Default Build Context option and specify Build Context), then it can find the aspnet-core-dotnet-core/aspnet-core-dotnet-core.csproj file

Resources