<p>just playing around a little bit.
I got a Visual Studio Solution, containing 3 projects.
All of the three are needed.
One project ("one") is the UI of the application. It contains static files in wwwroot of course.</p>

<p>I want to dockerize the application.
The Dockerfile here works.
Then I load this image via kubernetes on a Ubuntu Server.</p>

<p>No problem here, the container is running and serving requests.</p>

<p>But it is not serving the static files at all. All these file requests result in a 404 HTTP error. The web site looks like rubbish (but loads, though).</p>

<p>So i logged in to the container and started observing the contents of /app. No directory called "wwwroot" here. Also not the subdirectories.
I am not sure, if the wwwroot directory belongs here? Or is the directory included in the dll of the application?</p>

<p>After searching a lot (also found some helpful questions here on StackOverflow), I found out that files are included to the building process automatically. No need to define them separately in the csproj file. But if I do, it results in an error like "Duplicate files included" or something like that.</p>

<p>Here is the Dockerfile:</p>

<pre><code>FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY one/one.csproj one/
COPY two/two.csproj two/
COPY three/three.csproj three/
COPY . ./

WORKDIR "/src/one"
RUN dotnet build -c Release -o /app
WORKDIR "/src/two"
RUN dotnet build -c Release -o /app
WORKDIR "/src/three"
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "one.dll"]
</code></pre>

<p>Yes, I am using UseStaticFiles:</p>

<pre class="lang-cs prettyprint-override"><code>public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
    }
    // IMPORTANT: This session call MUST go before UseMvc()
    app.UseSession();
    app.UseStaticFiles();
    ...
</code></pre>

<p>And the static files are (mostly) all accessed with correct case sensitivity. But as I already said, <em>none</em> of the static files can be accessed.</p>

<p>In the Views, my app includes the CSS files like this:</p>

<pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;link rel="stylesheet" href="~/framework/1.css"&gt;
    &lt;link rel="stylesheet" href="~/framework/2.css" media="screen,projection"&gt;
    ...
</code></pre>

<p>While, running inside docker, it results in an HTML Output of this:</p>

<pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;link rel="stylesheet" href="/framework/1.css"&gt;
    &lt;link rel="stylesheet" href="/framework/2.css" media="screen,projection"&gt;
    ...
</code></pre>

<p>See the missing tilde ~ ?</p>

<p>How can the static files be included into the docker image?</p>

<p>Thank you! xola</p>

<p>Okay, now I found out myself.</p>

<p>The error was in the Dockerfile itself.
I needed to explicitly say, which csproj file to build and which one to publish. This is what I learned <a href="https://medium.com/@wcproxd/asp-net-core-and-docker-a-step-by-step-guide-a253062b1a9a" rel="noreferrer">here</a>.</p>

<p>Actually, no need to define something like "include this file, and this directory" in the csproj file.</p>

<p>And it is actually important to say, that the wwwroot directory is NOT compiled into the dll. It exists inside the /app folder in the container (that info I couldn't find anywhere, but I got a hint <a href="https://medium.com/@alcalawilfre/asp-net-core-with-docker-a-beginers-guide-4f490f644a89" rel="noreferrer">here</a>).</p>

<p>This also gives the ability to map an external folder to the container (so you can edit the static files without having to re-dockerize it over and over again - of course this is not meant for production environments).</p>

<p>Also important to say is, that for production environments and generally for all static files you don't want to come into the image (like source SCSS, un-<a href="https://obfuscator.io/" rel="noreferrer">obfuscated</a> JS, temporary files, copies of backups of copies of a file, and so on), a .dockerignore file should be used.</p>

<p>If you do not, the static files may be accessible directly via the browser, because they come directly into the wwwroot directory.</p>

<p>So here is my working Dockerfile.</p>

<pre><code>FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY all.sln ./    # not sure if I need this
COPY one/one.csproj one/
COPY two/two.csproj two/
COPY three/three.csproj three/
COPY . ./

RUN dotnet build "/src/one/one.csproj" -c Release -o /app
RUN dotnet build "/src/two/two.csproj" -c Release -o /app
RUN dotnet build "/src/three/three.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "/src/one/one.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "one.dll"]
</code></pre>

<p>Hope my explanations help others with this problem in future.</p>

<p>Thank you! xola</p>
