第5章 コンテナーでの .NET Core 3.1 アプリケーションの実行
dotnet/dotnet-31-runtime-rhel7 イメージを使用して、Linux コンテナーで事前コンパイルされたアプリケーションを実行します。
前提条件
事前設定されたコンテナー。
以下の例では podman を使用しています。
手順
オプション: 別のプロジェクトのディレクトリーにいて、ネストされたプロジェクトを作成したくない場合は、プロジェクトの親ディレクトリーに戻ります。
$ cd ..
mvc_runtime_exampleという名前のディレクトリーに新しい MVC プロジェクトを作成します。$ dotnet new mvc --output mvc_runtime_exampleプロジェクトを公開します。
$ dotnet publish mvc_runtime_example -f netcoreapp3.1 -c ReleaseDockerfileを作成します。$ cat > Dockerfile <<EOF FROM registry.redhat.io/dotnet/dotnet-31-runtime-rhel7 ADD bin/Release/netcoreapp3.1/publish/ . CMD ["dotnet", "mvc_runtime_example.dll"] EOF
イメージを構築します。
$ podman build -t dotnet-31-runtime-example .
注記unable to retrieve auth token: invalid username/passwordメッセージを含むエラーが発生した場合は、registry.redhat.ioサーバーの認証情報を提供する必要があります。podman login registry.redhat.ioコマンドを使用してログインします。認証情報は通常、Red Hat カスタマーポータルで使用されるものと同じです。イメージを実行します。
$ podman run -d -p8080:8080 dotnet-31-runtime-example
検証手順
コンテナーで実行されているアプリケーションを表示します。
$ xdg-open http://127.0.0.1:8080