DEV Community

Cover image for Steps for Deploying a Blazor as Static Site with Docker and Nginx
gopkumr
gopkumr

Posted on

4 3

Steps for Deploying a Blazor as Static Site with Docker and Nginx

Step 1 Publish the Blazor WebAssembly project

Publish the project from Visual Studio,this ensures that the projects is linked which removes all the unwanted dependencies from the output, reducing the size of the assemblies created.

Step 2 Create a dockerfile

The docker file is very straightforward, pull the nginx image and copy the published Blazor WebAssembly file from the WWWRoot folder to the html folder in nginx

FROM nginx:alpine
EXPOSE 80
COPY bin/Release/netcoreapp3.1/publish/wwwroot /usr/share/nginx/html
Enter fullscreen mode Exit fullscreen mode

Step 3 Build the docker image

use the below command

docker build --tag blazorstatic . 
Enter fullscreen mode Exit fullscreen mode

Step 4 Run the docker container

Run the docker container mapping the port exposed from the container to a port on the host

 docker run -p 8080:80 blazorstatic   
Enter fullscreen mode Exit fullscreen mode

Step 5 Access the Blazor WebApp from browser

Access the URL https://localhost:8080 which loads the WebApp
Alt Text

Source code for both ASPNet hosting and Static Website Hosting is available in Github: https://github.com/gopkumr/BlazorTourOfHeroes.git
Branch: Perf

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay