第5章 コンテナーでの .NET 5.0 アプリケーションの実行
ubi8/dotnet-50-runtime
イメージを使用して、Linux コンテナー内で事前にコンパイルされたアプリケーションを実行します。
前提条件
事前設定されたコンテナー。
以下の例では podman を使用しています。
手順
オプション: 別のプロジェクトのディレクトリーにあり、ネストされたプロジェクトを作成したくない場合は、プロジェクトの親ディレクトリーに戻ります。
# cd ..
mvc_runtime_example
という名前のディレクトリーに新しい MVC プロジェクトを作成します。$ dotnet new mvc --output mvc_runtime_example
プロジェクトを公開します。
$ dotnet publish mvc_runtime_example -f net5.0 -c Release
Dockerfile
を作成します。$ cat > Dockerfile <<EOF FROM registry.access.redhat.com/ubi8/dotnet-50-runtime ADD bin/Release/net5.0/publish/ . CMD ["dotnet", "mvc_runtime_example.dll"] EOF
イメージを構築します。
$ podman build -t dotnet-50-runtime-example .
イメージを実行します。
$ podman run -d -p8080:8080 dotnet-50-runtime-example
検証手順
コンテナーで実行されているアプリケーションを表示します。
$ xdg-open http://127.0.0.1:8080