Skip to content

Commit 6ee77e6

Browse files
jterry75galvesribeiro
authored andcommitted
Update readme to include certificate validation examples. (#283)
Ref: #278
1 parent 82ab425 commit 6ee77e6

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

README.md

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
# .NET Client for Docker Remote API
22

3-
This library allows you to interact with [Docker Remote API][docker-remote-api] endpoints in your .NET applications.
3+
This library allows you to interact with [Docker Remote API][docker-remote-api] endpoints in your .NET applications.
44

55
It is fully asynchronous, designed to be non-blocking and object-oriented way to interact with your Docker daemon programmatically.
66

77
**Versioning:** For example, `v2.124.0` supports `v1.24` of Docker Remote API.
88

99
## Installation
1010

11-
You can add this library to your project using [NuGet][nuget]. This is the only method this library is currently distributed unless
12-
you choose to build your own binaries using source code.
11+
You can add this library to your project using [NuGet][nuget].
1312

14-
**Package Manager Console**
13+
**Package Manager Console**
1514
Run the following command in the “Package Manager Console”:
1615

1716
PM> Install-Package Docker.DotNet
1817

19-
**Visual Studio**
18+
**Visual Studio**
2019
Right click to your project in Visual Studio, choose “Manage NuGet Packages” and search for ‘Docker.DotNet’ and click ‘Install’.
2120
([see NuGet Gallery][nuget-gallery].)
2221

23-
**.NET Core Command Line Interface**
22+
**.NET Core Command Line Interface**
2423
Run the following command from your favourite shell or terminal:
2524

2625
dotnet add package Docker.DotNet
2726

27+
**Development Builds**
28+
29+
![](https://ci.appveyor.com/api/projects/status/github/Microsoft/Docker.DotNet?branch=master&svg=true)
30+
31+
If you intend to use development builds of Docker.DotNet and don't want to compile the code yourself you can add the package source below to Visual Studio or your Nuget.Config.
32+
33+
> https://ci.appveyor.com/nuget/docker-dotnet-hojfmn6hoed7
34+
2835
## Usage
2936

3037
You can initialize the client like the following:
@@ -93,7 +100,7 @@ killing it. If you like to cancel the waiting, you can use the CancellationToken
93100

94101
#### Example: Dealing with Stream responses
95102

96-
Some Docker API endpoints are designed to return stream responses. For example
103+
Some Docker API endpoints are designed to return stream responses. For example
97104
[Monitoring Docker events](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/monitor-docker-s-events)
98105
continuously streams the status in a format like :
99106

@@ -135,7 +142,21 @@ The `CertFile` in the example above should be a .pfx file (PKCS12 format), if yo
135142

136143
openssl pkcs12 -export -inkey key.pem -in cert.pem -out key.pfx
137144

138-
(Here, your private key is key.pem, public key is cert.pem and output file is named key.pfx.) This will prompt a password for PFX file and then you can use this PFX file on Windows. If the certificate is self-signed, your application may reject the server certificate, in this case you might want to disable server certificate validation: `ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;`
145+
(Here, your private key is key.pem, public key is cert.pem and output file is named key.pfx.) This will prompt a password for PFX file and then you can use this PFX file on Windows. If the certificate is self-signed, your application may reject the server certificate, in this case you might want to disable server certificate validation:
146+
```c#
147+
//
148+
// There are two options to do this.
149+
//
150+
151+
// You can do this globally for all certificates:
152+
// (Note: This is not available on netstandard1.6)
153+
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
154+
155+
// Or you can do this on a credential by credential basis:
156+
var creds = new CertificateCredentials(...);
157+
creds.ServerCertificateValidationCallback += (o, c, ch, er) => true;
158+
159+
```
139160

140161
#### Example: Basic HTTP Authentication to Docker
141162

@@ -163,13 +184,13 @@ DockerClient client = config.CreateClient(new Version(1, 16));
163184
```
164185

165186
### Error Handling
166-
187+
167188
Here are typical exceptions thrown from the client library:
168189

169190
* **`DockerApiException`** is thrown when Docker API responds with a non-success result. Subclasses:
170191
* **``DockerContainerNotFoundException``**
171192
* **``DockerImageNotFoundException``**
172-
* **`TaskCanceledException`** is thrown from `System.Net.Http.HttpClient` library by design. It is not a friendly exception, but it indicates your request has timed out. (default request timeout is 100 seconds.)
193+
* **`TaskCanceledException`** is thrown from `System.Net.Http.HttpClient` library by design. It is not a friendly exception, but it indicates your request has timed out. (default request timeout is 100 seconds.)
173194
* Long-running methods (e.g. `WaitContainerAsync`, `StopContainerAsync`) and methods that return Stream (e.g. `CreateImageAsync`, `GetContainerLogsAsync`) have timeout value overridden with infinite timespan by this library.
174195
* **`ArgumentNullException`** is thrown when one of the required parameters are missing/empty.
175196
* Consider reading the [Docker Remote API reference][docker-remote-api] and source code of the corresponding method you are going to use in from this library. This way you can easily find out which parameters are required and their format.

0 commit comments

Comments
 (0)