LoginSignup
1
0

More than 1 year has passed since last update.

App Service の Web App for Container で .Net 6 Preview を試してみた

Last updated at Posted at 2021-04-18

背景と目的

2021年4月現在、.NET 6 Preview は App Service でサポートされていませんが、Web App for Container なら .NET 6 Preview を動かすことが可能なのではないかと思い、試してみました。

前提条件

.NET 6 環境は、.Net 6.0.0 Preview 2 を Visual Studio Code から Docker 利用してみた で作成した環境を使用します。

その他コマンドの実施環境は、Mac + Azure CLI です。

zsh
% sw_vers
ProductName:    macOS
ProductVersion: 11.2.3
BuildVersion:   20D91

% az version                            
{
  "azure-cli": "2.21.0",
  "azure-cli-core": "2.21.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

実施内容

VSCode の .NET 6 環境で MVC アプリを作成して動作確認を行います。

bash
$ dotnet new mvc -n mvcapp

$ cd mvcapp

$ cat << EOF > Views/Home/Index.cshtml
@using System.Runtime.InteropServices
@{
    ViewData["Title"] = "Home";
}
<div class="text-center">
    <h5>Environment</h5>
    <p>@RuntimeInformation.FrameworkDescription (@RuntimeInformation.ProcessArchitecture)</p>
    <p>@RuntimeInformation.OSDescription</p>
</div>
EOF

$ dotnet run

# http://localhost:5000 をブラウザで確認します。
# 問題なkれば、Ctrl+C で終了します。

$ dotnet publish -c Release

$ ls -l bin/Release/net6.0/publish/

VSCode の Docker 環境から抜けて、上で作成した mvcapp ディレクトリまで移動して Mac 上で作業します。

zsh
% cat <<EOF > Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:6.0
COPY bin/Release/net6.0/publish/ App/
WORKDIR /App
ENTRYPOINT ["dotnet", "mvcapp.dll"]
EOF

% az group create \
  --name AppSvc-DockerTutorial-rg \
  --location japaneast

% az acr create \
  --name mnrappsvc \
  --resource-group AppSvc-DockerTutorial-rg \
  --sku Basic \
  --admin-enabled true

# いつもなら下記コマンドで ACR へイメージをプッシュしますが、今回はもっと簡単に az acr build を使用します。
# docker login mnrappsvc.azurecr.io \
#   --username mnrappsvc \
#   --password $(az acr credential show \
#     --resource-group AppSvc-DockerTutorial-rg \
#     --name mnrappsvc \
#     --query "passwords[0].value" \
#     --output tsv)
# docker build --tag mvcapp .
# docker tag mvcapp mnrappsvc.azurecr.io/mvcapp:latest
# docker push mnrappsvc.azurecr.io/mvcapp:latest

% az acr build \
  --file Dockerfile \
  --registry mnrappsvc \
  --image mvcapp .

% az appservice plan create \
  --name AppSvc-DockerTutorial-plan \
  --resource-group AppSvc-DockerTutorial-rg \
  --is-linux

% az webapp create \
  --resource-group AppSvc-DockerTutorial-rg \
  --plan AppSvc-DockerTutorial-plan \
  --name mnrappsvc \
  --deployment-container-image-name mnrappsvc.azurecr.io/mvcapp:latest

% az webapp identity assign \
  --resource-group AppSvc-DockerTutorial-rg \
  --name mnrappsvc

% az role assignment create \
  --assignee $(az webapp identity show \
    --resource-group AppSvc-DockerTutorial-rg \
    --name mnrappsvc \
    --query principalId \
    --output tsv) \
  --scope $(az acr show \
    --name mnrappsvc \
    --resource-group AppSvc-DockerTutorial-rg \
    --query id \
    --output tsv) \
  --role "AcrPull"

% curl $(az webapp show \
  --name mnrappsvc \
  --resource-group AppSvc-DockerTutorial-rg \
  --query defaultHostName \
  --output tsv)

# リソースをクリーンアップする
% az group delete \
  --name AppSvc-DockerTutorial-rg

実施結果

.NET 6 Preview を App Service で動かすことが出来ました!

参考

Running .NET 6 (Preview) on App Service

カスタム コンテナーを使用してカスタム ソフトウェアを Azure App Service に移行する

チュートリアル: NET Core アプリのコンテナー化

ASP.NET Core 向けの Docker イメージ

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0