Skip to content

Commit

Permalink
Dockerizing ,NET Core Hello World
Browse files Browse the repository at this point in the history
  • Loading branch information
sadukie committed Jun 30, 2022
1 parent bc82553 commit 679bdc2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Start with the .NET SDK for building the app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
# Work within a folder named `/source`
WORKDIR /source

# Copy everything in this project and build app
COPY . ./dotnetcore-docs-hello-world/
WORKDIR /source/dotnetcore-docs-hello-world
RUN dotnet publish -c release -o /app

# final stage/image
# We're using a tag that is explicitly a Windows container
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app ./

# Start the app
ENTRYPOINT ["dotnet", "dotnetcoresample.dll"]
4 changes: 3 additions & 1 deletion Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
@page
@model IndexModel
@{
@{
ViewData["Title"] = "Home page";
}

<div class="text-center">
<h1 class="display-4">Hello World from .Net 6</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<hr />
<div>Host operating system: @Model.OSVersion</div>
</div>
6 changes: 5 additions & 1 deletion Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Runtime.InteropServices;

namespace dotnetcoresample.Pages;

public class IndexModel : PageModel
{

public string OSVersion { get; set; }

private readonly ILogger<IndexModel> _logger;

public IndexModel(ILogger<IndexModel> logger)
Expand All @@ -14,6 +18,6 @@ public IndexModel(ILogger<IndexModel> logger)

public void OnGet()
{

this.OSVersion = RuntimeInformation.OSDescription;
}
}

0 comments on commit 679bdc2

Please sign in to comment.