Hosting endpoints in Docker containers provides self-contained artifacts that can be deployed to multiple environments or managed by orchestration technologies such as Kubernetes. To create and host an endpoint in a Docker container, use the dotnet new
template from the ParticularTemplates package. The generated project includes all required endpoint setup infrastructure, along with a Dockerfile
needed to build and deploy a container hosting one endpoint.
Template overview
The nsbendpoint
template creates a project that contains all of the files necessary to build an endpoint that can be deployed to Docker if the Docker container hosting model is chosen.
See details on the dotnet new nsbendpoint
command for more.
license.xml
Each Docker container must include a license.
file. A placeholder for this file is created when the template is used to generate a new endpoint project. Before building the Docker container, this placeholder must be replaced with a valid license.
.
An endpoint running in Docker will look for the license.
file in the same locations as it would in any other hosting scenario. By default, the dotnet new
template places the license.
in the correct location within the Docker image.
Dockerfile
This file contains the instructions for compiling the endpoint and creating the Docker image.
The endpoint will be hosted in a container that is based on the mcr.
image. After the image is built, it contains the compiled artifacts of the endpoint project and is configured to launch the endpoint when the container runs.
To compile the endpoint and build the Docker image, run the following command:
docker build -f Dockerfile -t MyEndpoint ./..
This step compiles and publishes the endpoint in Release
mode:
RUN dotnet publish -c Release -o /app
The compiled endpoint is then added to the Docker image, and the container is configured to start the endpoint when it runs:
COPY --from=build /app .
ENTRYPOINT ["dotnet", "MyEndpoint.dll"]
Program.cs
The EndpointConfiguration
for the endpoint is defined in the template using the .
method. The generated code includes TODO
comments to guide further customization—these should be completed to configure the endpoint appropriately.
Additional methods are available to handle endpoint failures and exceptions. These should be modified as needed to suit the specific behavior of the endpoint.