此内容没有您所选择的语言版本。
Chapter 5. Running .NET 5.0 applications in containers
Use the ubi8/dotnet-50-runtime
image to run a precompiled application inside a Linux container.
Prerequisites
Preconfigured containers.
The following example uses podman.
Procedure
Optional: If you are in another project’s directory and do not wish to create a nested project, return to the parent directory of the project:
cd ..
# cd ..
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a new MVC project in a directory called
mvc_runtime_example
:dotnet new mvc --output mvc_runtime_example
$ dotnet new mvc --output mvc_runtime_example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Publish the project:
dotnet publish mvc_runtime_example -f net5.0 -c Release
$ dotnet publish mvc_runtime_example -f net5.0 -c Release
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
Dockerfile
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build your image:
podman build -t dotnet-50-runtime-example .
$ podman build -t dotnet-50-runtime-example .
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run your image:
podman run -d -p8080:8080 dotnet-50-runtime-example
$ podman run -d -p8080:8080 dotnet-50-runtime-example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification steps
View the application running in the container:
xdg-open http://127.0.0.1:8080
$ xdg-open http://127.0.0.1:8080
Copy to Clipboard Copied! Toggle word wrap Toggle overflow