第5章 コンテナーでの .NET 10.0 アプリケーションの実行
ubi9/dotnet-100-aspnet イメージを使用して、Linux コンテナー内で ASP.NET Core アプリケーションを実行できます。
ASP.NET Core 以外の.NET アプリケーションの場合は、より小さい ubi9/dotnet-100-runtime イメージを使用します。
.NET SDK から直接 ASP.NET Core アプリケーションのコンテナーイメージを構築し、Podman を使用して実行する方法について説明します。
前提条件
- .NET 10.0 SDK がインストールされている。
- Podman がインストールされている。
-
ContainerBaseImage属性 (registry.access.redhat.com) で指定されたコンテナーレジストリーへのネットワークアクセスがある。
手順
mvc_runtime_exampleという名前のディレクトリーに新しい ASP.NET Core MVC プロジェクトを作成します。dotnet new mvc --output mvc_runtime_example
$ dotnet new mvc --output mvc_runtime_exampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow プロジェクトを公開します。
dotnet publish mvc_runtime_example -f net10.0 /p:PublishProfile=DefaultContainer /p:ContainerBaseImage=registry.access.redhat.com/ubi9/dotnet-100-aspnet:latest
$ dotnet publish mvc_runtime_example -f net10.0 /p:PublishProfile=DefaultContainer /p:ContainerBaseImage=registry.access.redhat.com/ubi9/dotnet-100-aspnet:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow イメージを実行します。
podman run --rm -p 8080:8080 mvc_runtime_example
$ podman run --rm -p 8080:8080 mvc_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