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