Skip to content

Commit

Permalink
Merge pull request Azure-Samples#3 from sadukie/master
Browse files Browse the repository at this point in the history
Adding Docker files for Linux and Windows for Azure App Service .NET Core sample app
  • Loading branch information
cephalin authored Jul 1, 2022
2 parents bc82553 + 7014ec7 commit 899d1d8
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
22 changes: 22 additions & 0 deletions Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app ./

# Expose port 80
# This is important in order for the Azure App Service to pick up the app
ENV PORT 80
EXPOSE 80

# Start the app
ENTRYPOINT ["dotnet", "dotnetcoresample.dll"]
26 changes: 26 additions & 0 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Start with the .NET SDK for building the app
# Using an explicit Windows Server tag
# We are using Windows Nanoserver, a headless server for hosting apps with IIS
FROM mcr.microsoft.com/dotnet/sdk:6.0-nanoserver-ltsc2022 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.6-nanoserver-ltsc2022

WORKDIR /app
COPY --from=build /app ./

# Expose port 80
# This is important in order for the Azure App Service to pick up the app
ENV PORT 80
EXPOSE 80

# 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>
7 changes: 5 additions & 2 deletions 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 { return RuntimeInformation.OSDescription; } }

private readonly ILogger<IndexModel> _logger;

public IndexModel(ILogger<IndexModel> logger)
Expand All @@ -13,7 +17,6 @@ public IndexModel(ILogger<IndexModel> logger)
}

public void OnGet()
{

{
}
}
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
# .Net 6 Hello World
# .NET 6 Hello World

This sample demonstrates a tiny Hello World .NET Core app for [App Service Web App](https://docs.microsoft.com/azure/app-service-web).
This sample demonstrates a tiny Hello World .NET Core app for [App Service Web App](https://docs.microsoft.com/azure/app-service-web). This sample can be used in a .NET Azure App Service app as well as in a Custom Container Azure App Service app.

## Log in to Azure Container Registry

Using the Azure CLI, log in to the Azure Container Registry (ACR):

```azurecli
az acr login -n <your_registry_name>
```

## Running in a Docker Container

This repository contains 2 Dockerfiles, a Linux container and a Windows container.

### Publish the Windows image to your Registry

To build the Windows image locally and publish to ACR, run the following command:

```docker
docker build -f Dockerfile.windows -t dotnetcore-docs-hello-world-windows .
docker tag dotnetcore-docs-hello-world-windows <your_registry_name>.azurecr.io/dotnetcore-docs-hello-world-windows:latest
docker push <your_registry_name>.azurecr.io/dotnetcore-docs-hello-world-windows:latest
```

### Publish the Linux image to your Registry

To build the Windows image locally and publish to ACR, run the following command:

```docker
docker build -f Dockerfile.linux -t dotnetcore-docs-hello-world-linux .
docker tag dotnetcore-docs-hello-world-windows <your_registry_name>.azurecr.io/dotnetcore-docs-hello-world-linux:latest
docker push <your_registry_name>.azurecr.io/dotnetcore-docs-hello-world-linux:latest
```

# Contributing

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

0 comments on commit 899d1d8

Please sign in to comment.