第 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)中指定的容器 registry。
流程
在名为
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