Microsoft が提供しているチュートリアルを先にすすめる

前回、 ASP.NET Core SDK コンテナにディレクトリをマウントする ではディレクトリをマウントすることで、ホスト側でソースの変更ができ、ホスト側にアプリのデータを残せるようになった。

なので今回は Microsoft のチュートリアル ASP.NET Tutorial | Hello World in 10 minutes | .NET を最後まで進める。

参考:

ファイルを変更する

Edit your code

Open Pages/Index.cshtml in any text editor and replace all of the code with the following, then save the file.

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="text-center">
    <h1>Hello, world!</h1>
    <p>The time on the server is @DateTime.Now</p>
</div>

Re-run your app

End the previous dotnet run command that is running the site locally, then run the following command to re-launch the site:

dotnet run

やってみる。まずは donnet SDK コンテナを動作させる。

$ ./run_SDK_container.sh 
/ # 

起動した。別のターミナルからホスト側で Pages/Index.cshtml を編集する。

$ vimr WebApp/Pages/Index.cshtml
@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
    <p>この行を追加した。</p>
</div>

変更した。コンテナ側で WebApp を動作させてみる。

# cd home/WebApp/
# dotnet run
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
      Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {1a5b21f9-802c-405d-a620-1a5c239e4953} may be persisted to storage in unencrypted form.
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://0.0.0.0:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/WebApp
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect.

動作したらしい。ホスト側から http://localhost:5000 へアクセスして確認する。

無事に変更が反映された