2.4. コンテナーでの .NET Core 2.1 アプリケーションの実行
dotnet/dotnet-21-runtime-rhel7 イメージを使用して、Linux コンテナー内でプリコンパイルされたアプリケーションを実行します。
前提条件
事前設定されたコンテナー。
以下の例では podman を使用しています。
手順
mvc_runtime_exampleという名前のディレクトリーに新しい MVC プロジェクトを作成します。dotnet new mvc --output mvc_runtime_example --no-restore
$ dotnet new mvc --output mvc_runtime_example --no-restoreCopy to Clipboard Copied! Toggle word wrap Toggle overflow プロジェクトを復元し、公開します。
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
$ 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.AppCopy to Clipboard Copied! Toggle word wrap Toggle overflow Dockerfileを作成します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow イメージを構築します。
podman build -t dotnet-21-runtime-example .
$ podman build -t dotnet-21-runtime-example .Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注記unable to retrieve auth token: invalid username/passwordメッセージを含むエラーが発生した場合は、registry.redhat.ioサーバーの認証情報を提供する必要があります。podman login registry.redhat.ioコマンドを使用してログインします。認証情報は通常、Red Hat カスタマーポータルで使用されるものと同じです。イメージを実行します。
podman run -d -p8080:8080 dotnet-21-runtime-example
$ podman run -d -p8080:8080 dotnet-21-runtime-exampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow
検証手順
コンテナーで実行されているアプリケーションを表示します。
xdg-open http://127.0.0.1:8080
$ xdg-open http://127.0.0.1:8080Copy to Clipboard Copied! Toggle word wrap Toggle overflow