title: Blazor WebAssembly App with docker support (linux)
body: <p>Today I have a question which is one of those questions, that you always did want to know but you were always afraid to ask;) But this question is also correlated with BlazorWebAssembly app docker support. So maybe I will describe what I did.</p>
  <p>SO I did want to play a little bit with cutting edge blazor and of course .NET 5.0 (my last &quot;cutting edge technology&quot; was ASP.NET MVC - so yeah, it have been a while :) )</p>
  <p>In the beginning i didn't quite know what those option correlated with Blazor was for. So i've chosen:</p>
  <p><a href="https://i.stack.imgur.com/fuS8j.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fuS8j.png" alt="enter image description here" /></a></p>
  <p>You can spot, that the option &quot;Enable Docker Support&quot; is greyed out. So it was like &quot;docker support problem preview&quot; :)</p>
  <p>I didn't know what option: &quot;ASP.NET Core hosted&quot; stand for, so I didn't use it (and it was a mistake) Once you check this option it will create one server app, one client (Blazor) one and one shared (which is for model purposes between them)</p>
  <p>I didn't know that, so I did have to add on my own WebApi project and some project for the model :)</p>
  <p>Now, the next step was to add docker support (which surprisingly is possible)</p>
  <p><a href="https://i.stack.imgur.com/CLt9Z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CLt9Z.png" alt="enter image description here" /></a></p>
  <p>And this created a docker file:</p>
  <pre><code>#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:5.0-buster-slim AS base
  WORKDIR /app
  EXPOSE 80
  EXPOSE 443
  
  FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
  WORKDIR /src
  COPY [&quot;BlazorApp/BlazorApp.csproj&quot;, &quot;BlazorApp/&quot;]
  COPY [&quot;../SearchMovies.Model/SearchMovies.Model.csproj&quot;, &quot;../SearchMovies.Model/&quot;]
  RUN dotnet restore &quot;BlazorApp/BlazorApp.csproj&quot;
  COPY . .
  WORKDIR &quot;/src/BlazorApp&quot;
  RUN dotnet build &quot;BlazorApp.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;BlazorApp.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;BlazorApp.dll&quot;]
  </code></pre>
  <p>Starting such app will end with something like that:</p>
  <pre><code>docker exec -i -e ASPNETCORE_HTTPS_PORT=&quot;32776&quot; -w &quot;/app&quot; 28d444a42ceefdf124b29f9f542f423aa931e521d077bbfeb19e5da7644a5e25 sh -c &quot;&quot;dotnet&quot; --additionalProbingPath /root/.nuget/fallbackpackages2 --additionalProbingPath /root/.nuget/fallbackpackages --additionalProbingPath /root/.nuget/fallbackpackages3  \&quot;/app/bin/Debug/net5.0/BlazorApp.dll\&quot; | tee /dev/console&quot;
  Cannot use file stream for [/app/bin/Debug/net5.0/BlazorApp.deps.json]: No such file or directory
  A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/bin/Debug/net5.0/'.
  Failed to run as a self-contained app.
    - The application was run as a self-contained app because '/app/bin/Debug/net5.0/BlazorApp.runtimeconfig.json' was not found.
    - If this should be a framework-dependent app, add the '/app/bin/Debug/net5.0/BlazorApp.runtimeconfig.json' file and specify the appropriate framework.
  </code></pre>
  <p>I've already googled it, and the answer was: yeah, it is normal behaviour. Blazor is just a piece of static files (whicha are only &quot;smartly&quot; produced) So that is why it doesn't work. Tbh, I hear them, but still... Why o why?</p>
  <p>I've googled it a little bit. I found some nice article about Blazor Webassembly here:</p>
  <p><a href="https://medium.com/@waelkdouh/hosting-containerized-client-side-blazor-applications-on-azure-e090af738619" rel="noreferrer">https://medium.com/@waelkdouh/hosting-containerized-client-side-blazor-applications-on-azure-e090af738619</a></p>
  <p>Some fun fact at the begining (the quote from the article)</p>
  <blockquote>
  <p>Note: I imagine this checkbox will be enabled sometime in the future</p>
  </blockquote>
  <p>So guys, just to calm you. We are definively not in the futrue :)</p>
  <p>So i've changed the docker file. And if i remember correctly - runing it &quot;manually&quot; as in the article by using &quot;docker build&quot; and &quot;docker run&quot; it started successfuly.</p>
  <p>But when trying to hit &quot;Debug&quot; (or start without debuging) the error was the same as previously.
  Here is the docker file proposed there (i've only changed the version to 5.0 and changed publish to run only on the project):</p>
  <pre><code>FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster-slim AS build-env
  WORKDIR /app
  COPY . ./
  RUN dotnet publish &quot;BlazorApp/BlazorApp.csproj&quot; -c Release -o output
  
  FROM nginx:alpine
  WORKDIR /var/www/web
  COPY --from=build-env /app/output/wwwroot .
  COPY nginx.conf /etc/nginx/nginx.conf
  EXPOSE 80
  </code></pre>
  <p>So two attempts. I've checked also another cutting edge orchestration thingy called <strong>tye</strong>:</p>
  <p><a href="https://devblogs.microsoft.com/aspnet/introducing-project-tye/" rel="noreferrer">https://devblogs.microsoft.com/aspnet/introducing-project-tye/</a></p>
  <p>But it cannot handle the Blazor as well.</p>
  <p>I've even quickly created blazor app with ASP.NET Core hosted option. After <code>tye init</code>, <code>tye build</code> and <code>tye run</code> there are no bindings for the client project:</p>
  <p><a href="https://i.stack.imgur.com/Uyp4H.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Uyp4H.png" alt="enter image description here" /></a></p>
  <p>So maybe someone have some idea, what can i try?</p>
  <p>And the question mentioned at the very begining was regarding orchestration i suppose. Let's assume i have four projects in solution - for example, Blazor and three webapi`s. How to run everything so that it will automagically bind the endpoints. Because normally i have to add the url for endpoints like: &quot;https://localhost:5123/api/SomeService&quot;</p>
  <p>And docker at least when starting can assign different port numbers for those API's Changing in the code manually seems like the dummy thing to do.</p>
  <p>What is the best way to tackle such cases - where there is a lot o communications between endpoints and i want to start all of them and they will be automatically &quot;connected&quot; (meaning, they will know on which port the &quot;other&quot; service is)?</p>
  <p>Thanks in advance for anwsers on those two questions</p>