I'm using the FlightFinder sample for reproducing the problem.
https://github.com/aspnet/samples
or my fork: https://github.com/paulvanbladel/samples
steps to reproduce:
dotnet publish FlightFinder.Server/FlightFinder.Server.csproj -c release -o publish
dotnet FlightFinder.Server.dll
Unfortunately, this bug makes that blazor can't be used with docker (didn't try with windows images).
```
paul@ubuntu-desktop:~/github/samples/samples/aspnetcore/blazor/FlightFinder/FlightFinder.Server/publish$ dotnet FlightFinder.Server.dll
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/home/paul/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Unhandled Exception: System.ArgumentException: The path must be absolute.
Parameter name: root
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, PhysicalFilesWatcher physicalFilesWatcher)
at Microsoft.AspNetCore.Builder.BlazorAppBuilderExtensions.UseBlazor(IApplicationBuilder applicationBuilder, BlazorOptions options)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at FlightFinder.Server.Program.Main(String[] args) in /home/paul/github/samples/samples/aspnetcore/blazor/FlightFinder/FlightFinder.Server/Program.cs:line 14
Aborted (core dumped)
``
I have also encountered this issue, it appears to be related to the published files being split between wwwroot and dist under Docker/Linux, whereas when published on my local (Windows) machine, everything goes under dist.
Unfortunately I hadn't had a chance to investigate much further yet, but the following line appears to be the culprit:
FileProvider = new PhysicalFileProvider(config.WebRootPath)
The first line of the .blazor.config file is set to ., resulting in config.WebRootPath being .\wwwroot - Perhaps this could be fixed by resolving the absolute file path prior to passing to the PhysicalFileProvider ctor.
As a temporary workaround, I was able to get Blazor running under Docker by amending my Dockerfile as follows in order to move everything under dist and therefore preventing the second call to UseStaticFiles:
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
RUN mv -n wwwroot/* FlightFinder.Client/dist
RUN rm -rf wwwroot/
ENTRYPOINT ["dotnet", "FlightFinder.Server.dll"]
(Note, this only works when using docker-compose up, and does not work with debugging in Docker through Visual Studio)
@javiercn Can you take a look at what's happening here and how we might better work with Docker scenarios?
Perhaps this could be fixed by resolving the absolute file path prior to passing to the PhysicalFileProvider ctor.
Yes, we could definitely do that. Thanks for the info!
I have similar problem in Blazor 0.4.0 where I could not use published output for building docker container.
I generate build using dotnet publish from the blazorhosted template on Windows and try create Docker container using Alpine image.
The error which I receive
Microsoft.AspNetCore.Hosting.Internal.WebHost[6]
Application startup exception
System.ArgumentException: The directory name '/dist/' does not exist.
Parameter name: path
at System.IO.FileSystemWatcher..ctor(String path, String filter)
at System.IO.FileSystemWatcher..ctor(String path)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider.CreateFileWatcher(String root, ExclusionFilters filters)
at Microsoft.AspNetCore.Builder.BlazorAppBuilderExtensions.UseBlazor(IApplicationBuilder applicationBuilder, BlazorOptions options)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
the problem appears to be that blazor.config when running publish have following content
.
blazorhosted.Client\
but if I change content to
.
blazorhosted.Client/
then docker image start working.
I've just encountered this as well - and again, changing the trailing backslash to a forward slash seems to fix things.
I think it may be as simple as changing a \ to / in https://github.com/aspnet/Blazor/blob/d4b73de287396a299d8b1f322d8bd4ba5d02aa99/src/Microsoft.AspNetCore.Blazor.Build/targets/Publish.targets#L44
@SteveSandersonMS I think we should take a look at this one for 0.5.0.
This is a good candidate for up forcgrabs
The original issue reported here was already fixed in 0.5.0. The issue with the slash style is also now fixed in 9d6cc3d.
Most helpful comment
I have also encountered this issue, it appears to be related to the published files being split between
wwwrootanddistunder Docker/Linux, whereas when published on my local (Windows) machine, everything goes underdist.Unfortunately I hadn't had a chance to investigate much further yet, but the following line appears to be the culprit:
https://github.com/aspnet/Blazor/blob/dev/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs#L67
The first line of the
.blazor.configfile is set to., resulting inconfig.WebRootPathbeing.\wwwroot- Perhaps this could be fixed by resolving the absolute file path prior to passing to thePhysicalFileProviderctor.As a temporary workaround, I was able to get Blazor running under Docker by amending my Dockerfile as follows in order to move everything under
distand therefore preventing the second call toUseStaticFiles:(Note, this only works when using
docker-compose up, and does not work with debugging in Docker through Visual Studio)