第 5 章 在容器中运行 .NET 7.0 应用程序
使用 ubi8/dotnet-70-runtime
镜像在 Linux 容器内运行预编译的应用程序。
先决条件
预配置的容器。
以下示例使用 podman。
流程
可选: 如果您位于另一个项目的目录中,且不想创建嵌套项目,请返回到项目的父目录:
# cd ..
在名为
mvc_runtime_example
的目录中创建一个新的 MVC 项目:$ dotnet new mvc --output mvc_runtime_example
发布项目:
$ dotnet publish mvc_runtime_example -f net7.0 -c Release
创建
Dockerfile
:$ cat > Dockerfile <<EOF FROM registry.access.redhat.com/ubi8/dotnet-70-runtime ADD bin/Release/net7.0/publish/ . CMD ["dotnet", "mvc_runtime_example.dll"] EOF
构建镜像:
$ podman build -t dotnet-70-runtime-example .
运行您的镜像:
$ podman run -d -p8080:8080 dotnet-70-runtime-example
验证步骤
查看在容器中运行的应用程序:
$ xdg-open http://127.0.0.1:8080