Getting Started
Architecture
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Docker Container Host

Hosting endpoints in Docker containers provides self-contained artifacts that are deployable 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 in the ParticularTemplates package. The project that is created will have the required endpoint setup infrastructure in addition to the Dockerfile needed to create 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 have a license.xml file included in it. A placeholder for this file is created when the template is used to create a new endpoint. This file must be replaced with a valid license.xml file prior to building the Docker container.

An endpoint running in Docker will look for the license.xml file in the same locations as it would in any other hosting situation. By default, a project created using the dotnet new templates will put the license.xml file in the correct location in a 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.microsoft.com/dotnet/core/runtime:3.1 image. Once built, the container image contains the compiled artifacts of the endpoint project, and it will launch that endpoint when the container is run.

To compile the endpoint and create the Docker image, run the following command:

docker build -f Dockerfile -t MyEndpoint ./..

Building the container will compile and publish the endpoint in Release mode.

RUN dotnet publish -c Release -o /app

The compiled endpoint is added to the docker image, the endpoint is configured to start when the container is run, and the container is built.

COPY --from=build /app .
ENTRYPOINT ["dotnet", "MyEndpoint.dll"]

Program.cs

The EndpointConfiguration for the endpoint will be defined in the template in a .UseNServiceBus(…) method, and contains TODO statements that must be filled in.

There are also methods that handle endpoint failures and exceptions, which should be modified to fit the needs of the endpoint.

Samples

Related Articles