Additionally, let’s change the default welcome message in Index.cshtml file to show a welcome message like this:

<h1 class="display-4">Welcome to .NET 5.Zero on Google Cloud</h1>

After the modifications, you’ll be able to construct and run the app domestically. It ought to begin a server listening on port 8080:

> dotnet run

information: Microsoft.Internet hosting.Lifetime[0]

      Now listening on: http://0.0.0.0:8080

Containerize .NET 5.0 

To containerize the app, we are going to create a Dockerfile. One factor to remember is that with the discharge of .NET 5.0, all Docker tags for .NET Core 2.1/3.1 and .NET 5.Zero is printed to 1 set of unified Docker repositories (see 2375). The names of those repositories have been modified from the originals to not embody “core” within the identify. 

Right here’s the Dockerfile for our app utilizing the brand new dotnet/sdk and dotnet/aspnet base pictures with 5.Zero variations:

FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS construct

WORKDIR /app

COPY *.csproj ./

RUN dotnet restore

COPY . ./

WORKDIR /app

RUN dotnet publish -c Launch -o out

FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine AS runtime

WORKDIR /app

COPY --from=construct /app/out ./

ENTRYPOINT ["dotnet", "webapp-cloudrun.dll"]

Construct and save the Docker picture to Google Container Registry with Cloud Construct:

> gcloud builds submit --tag gcr.io/$GOOGLE_CLOUD_PROJECT/hello-dotnet5

Deploy to Cloud Run

Lastly, deploy to Cloud Run:

> gcloud run deploy --image gcr.io/$GOOGLE_CLOUD_PROJECT/hello-dotnet5

        --platform managed

        --allow-unauthenticated

In just a few seconds, it’s best to see the service deployed:

✓ Deploying... Executed.

✓ Creating Revision...

✓ Routing site visitors...

✓ Setting IAM Coverage...

Executed.

Service [hello-dotnet5] revision [hello-dotnet5-00002-tux] has been deployed and is serving 100 p.c of site visitors.

Service URL: https://hello-dotnet5-dhmnie7yqa-ew.a.run.app

And visiting the service URL will show our web page:



Leave a Reply

Your email address will not be published. Required fields are marked *