I'm trying to containerize a Blazor app knowing that I have the Server
project and the Client
project.
I wanted to know if I should right click on the Server
project and create a Dockerfile for just the server project knowing that Blazor is basically a 2 projects in 1 kind of project or does the Client
project also needs its own Dockerfile (and therefore they maybe need to be ran with Docker Compose to be able to communicate) ?
If you are using the blazor web app ,you just need to make sure you create the docker file for the main project.
Inside the generated docker file, you could find it will copy all the project which inculde the client project.
Inside the blazor web app, the server will also serve the client app, so no need to create the docker for each client and server.
More details, you could check this article and below docker file:
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["BlazorApp12/BlazorApp12/BlazorApp12.csproj", "BlazorApp12/BlazorApp12/"]
COPY ["BlazorApp12/BlazorApp12.Client/BlazorApp12.Client.csproj", "BlazorApp12/BlazorApp12.Client/"]
RUN dotnet restore "./BlazorApp12/BlazorApp12/BlazorApp12.csproj"
COPY . .
WORKDIR "/src/BlazorApp12/BlazorApp12"
RUN dotnet build "./BlazorApp12.csproj" -c $BUILD_CONFIGURATION -o /app/build
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./BlazorApp12.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BlazorApp12.dll"]