Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor WASM CSS Not loading on published container

I'm having issues with a Blazor WebAssembly project that don't render the css styles of the components with css isolation after I published to a docker container. In the development scenario works fine, but when I build it to a docker container it doesn't apply styles to my components. My docker file looks like this:

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build

COPY /src/SDK/XTOS.PlayerUI.SDK.csproj /src/SDK/XTOS.PlayerUI.SDK.csproj
RUN dotnet restore /src/SDK/XTOS.PlayerUI.SDK.csproj
COPY /src/SDK/ /src/SDK

COPY /src/WebClient/XTOS.PlayerUI.WebClient.csproj /src/WebClient/XTOS.PlayerUI.WebClient.csproj
RUN dotnet restore /src/WebClient/XTOS.PlayerUI.WebClient.csproj
COPY /src/WebClient/ /src/WebClient/

WORKDIR /src
RUN dotnet build WebClient/XTOS.PlayerUI.WebClient.csproj -c Release -o /app/build

FROM build AS publish
RUN dotnet publish /src/WebClient/XTOS.PlayerUI.WebClient.csproj -c Release -o /app/publish

FROM nginx:alpine AS final
WORKDIR /usr/share/nginx/html
COPY --from=publish /app/publish/wwwroot .
COPY nginx.conf /etc/nginx/nginx.conf

It is building with nginx for the serving of the files. The nginx conf file looks like this:

events { }
http {
    include mime.types;

    limit_req_zone $binary_remote_addr zone=one:10m rate=120r/s;

    server {
        listen 80;

        location / {
            root /usr/share/nginx/html;
            try_files $uri $uri/ /index.html =404;

            limit_req zone=one burst=60;
        }
    }
}

No errors occurs when loading the media, even the css files are received in the browser and are referenced in the of the index.html, but is like the components are not using them.

like image 440
Frank Raúl Pérez Pérez Avatar asked May 17 '26 08:05

Frank Raúl Pérez Pérez


1 Answers

The issue was solved by excluding the /bin and /obj folders from copying to the docker image.

like image 180
Frank Raúl Pérez Pérez Avatar answered May 19 '26 21:05

Frank Raúl Pérez Pérez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!