Ocelot.Provider.Docker
6.1.0
See the version list below for details.
dotnet add package Ocelot.Provider.Docker --version 6.1.0
NuGet\Install-Package Ocelot.Provider.Docker -Version 6.1.0
<PackageReference Include="Ocelot.Provider.Docker" Version="6.1.0" />
paket add Ocelot.Provider.Docker --version 6.1.0
#r "nuget: Ocelot.Provider.Docker, 6.1.0"
// Install Ocelot.Provider.Docker as a Cake Addin #addin nuget:?package=Ocelot.Provider.Docker&version=6.1.0 // Install Ocelot.Provider.Docker as a Cake Tool #tool nuget:?package=Ocelot.Provider.Docker&version=6.1.0
Ocelot docker provider
This package adds to the ocelot the ability to retrieve services from the labels of your docker containers.
Ocelot allows you to specify a service discovery provider and will use this to find the host and port for the downstream service Ocelot is forwarding a request to. At the moment this is only supported in the GlobalConfiguration section which means the same service discovery provider will be used for all Routes you specify a ServiceName for at Route level.
Please show the value
Choosing a project dependency could be difficult. We need to ensure stability and maintainability of our projects. Surveys show that GitHub stars count play an important factor when assessing library quality.
⭐ Please give this repository a star. It takes seconds and help thousands of developers! ⭐
Support development
It doesn't matter if you are a professional developer, creating a startup or work for an established company. All of us care about our tools and dependencies, about stability and security, about time and money we can safe, about quality we can offer. Please consider sponsoring to give me an extra motivational push to develop the next great feature.
If you represent a company, want to help the entire community and show that you care, please consider sponsoring using one of the higher tiers. Your company logo will be shown here for all developers, building a strong positive relation.
Installation
The library is available as a nuget package. You can install it as any other nuget package from your IDE, try to search by Ocelot.Provider.Docker
. You can find package details on this webpage.
// Package Manager
Install-Package Ocelot.Provider.Docker
// .NET CLI
dotnet add package Ocelot.Provider.Docker
// Package reference in .csproj file
<PackageReference Include="Ocelot.Provider.Docker" Version="6.0.0" />
Then add the following to your ConfigureServices method.
s.AddOcelot()
.AddDocker();
The following is required in the GlobalConfiguration. The Provider is required and if you do not specify a host and port the Docker default will be used.
"GlobalConfiguration": {
"UseServiceDiscovery": true,
"ServiceDiscoveryProvider": {
"Scheme": "unix",
"Host": "/var/run/docker.sock",
"Type": "Docker"
}
}
In order to tell Ocelot a Route is to use the service discovery provider for its host and port you must add the ServiceName and load balancer you wish to use when making requests downstream. At the moment Ocelot has a RoundRobin and LeastConnection algorithm you can use. If no load balancer is specified Ocelot will not load balance requests.
{
"DownstreamPathTemplate": "/v2/{everything}",
"DownstreamScheme": "http",
"UpstreamPathTemplate": "/petstore/{everything}",
"UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE" ],
"ServiceName": "petstore",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
}
When this is set up Ocelot will lookup the downstream host and port from the service discover provider and load balance requests across any available services. If you want to poll Docker for the latest services rather than per request (default behaviour) then you need to set the following configuration.
"GlobalConfiguration": {
"UseServiceDiscovery": true,
"ServiceDiscoveryProvider": {
"Scheme": "unix",
"Host": "/var/run/docker.sock",
"PollingInterval": 2000,
"Type": "PollDocker"
}
}
The polling interval is in milliseconds and tells Ocelot how often to call Docker for changes in service configuration.
Configuration
The following example implemented the docker provider.
version: '3.7'
services:
petstore:
image: swaggerapi/petstore
environment:
- SWAGGER_BASE_PATH=/v2
labels:
- ocelot.service=petstore
- ocelot.scheme=http
- ocelot.port=8080
If you have multiple networks, you must add the following label to select the correct network:
ocelot.scheme
How to Contribute
Everyone is welcome to contribute to this project! Feel free to contribute with pull requests, bug reports or enhancement suggestions.
Bugs and Feedback
For bugs, questions and discussions please use the GitHub Issues.
License
This project is licensed under MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- Docker.DotNet (>= 3.125.5)
- Ocelot (>= 18.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.