2.4. コンテナーでの .NET Core 2.1 アプリケーションの実行

dotnet/dotnet-21-runtime-rhel7 イメージを使用して、Linux コンテナー内でプリコンパイルされたアプリケーションを実行します。

前提条件

  • 事前設定されたコンテナー。

    以下の例では podman を使用しています。

手順

  1. mvc_runtime_example という名前のディレクトリーに新しい MVC プロジェクトを作成します。

    $ dotnet new mvc --output mvc_runtime_example --no-restore
  2. プロジェクトを復元し、公開します。

    $ dotnet restore mvc_runtime_example -r rhel.7-x64
    $ dotnet publish mvc_runtime_example -f netcoreapp2.1 -c Release -r rhel.7-x64 --self-contained false /p:MicrosoftNETPlatformLibrary=Microsoft.NETCore.App
  3. Dockerfile を作成します。

    $ cat > Dockerfile <<EOF
    FROM registry.redhat.io/dotnet/dotnet-21-runtime-rhel7
    
    ADD bin/Release/netcoreapp2.1/publish/ .
    
    CMD ["dotnet", "mvc_runtime_example.dll"]
    EOF
  4. イメージを構築します。

    $ podman build -t dotnet-21-runtime-example .
    注記

    unable to retrieve auth token: invalid username/password メッセージを含むエラーが発生した場合は、registry.redhat.io サーバーの認証情報を提供する必要があります。podman login registry.redhat.io コマンドを使用してログインします。認証情報は通常、Red Hat カスタマーポータルで使用されるものと同じです。

  5. イメージを実行します。

    $ podman run -d -p8080:8080 dotnet-21-runtime-example

検証手順

  • コンテナーで実行されているアプリケーションを表示します。

    $ xdg-open http://127.0.0.1:8080