|
1 | 1 | # .NET Client for Docker Remote API
|
2 | 2 |
|
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. |
4 | 4 |
|
5 | 5 | It is fully asynchronous, designed to be non-blocking and object-oriented way to interact with your Docker daemon programmatically.
|
6 | 6 |
|
7 | 7 | **Versioning:** For example, `v2.124.0` supports `v1.24` of Docker Remote API.
|
8 | 8 |
|
9 | 9 | ## Installation
|
10 | 10 |
|
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]. |
13 | 12 |
|
14 |
| - **Package Manager Console** |
| 13 | + **Package Manager Console** |
15 | 14 | Run the following command in the “Package Manager Console”:
|
16 | 15 |
|
17 | 16 | PM> Install-Package Docker.DotNet
|
18 | 17 |
|
19 |
| -**Visual Studio** |
| 18 | +**Visual Studio** |
20 | 19 | Right click to your project in Visual Studio, choose “Manage NuGet Packages” and search for ‘Docker.DotNet’ and click ‘Install’.
|
21 | 20 | ([see NuGet Gallery][nuget-gallery].)
|
22 | 21 |
|
23 |
| -**.NET Core Command Line Interface** |
| 22 | +**.NET Core Command Line Interface** |
24 | 23 | Run the following command from your favourite shell or terminal:
|
25 | 24 |
|
26 | 25 | dotnet add package Docker.DotNet
|
27 | 26 |
|
| 27 | +**Development Builds** |
| 28 | + |
| 29 | + |
| 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 | +
|
28 | 35 | ## Usage
|
29 | 36 |
|
30 | 37 | 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
|
93 | 100 |
|
94 | 101 | #### Example: Dealing with Stream responses
|
95 | 102 |
|
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 |
97 | 104 | [Monitoring Docker events](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/monitor-docker-s-events)
|
98 | 105 | continuously streams the status in a format like :
|
99 | 106 |
|
@@ -135,7 +142,21 @@ The `CertFile` in the example above should be a .pfx file (PKCS12 format), if yo
|
135 | 142 |
|
136 | 143 | openssl pkcs12 -export -inkey key.pem -in cert.pem -out key.pfx
|
137 | 144 |
|
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 | +``` |
139 | 160 |
|
140 | 161 | #### Example: Basic HTTP Authentication to Docker
|
141 | 162 |
|
@@ -163,13 +184,13 @@ DockerClient client = config.CreateClient(new Version(1, 16));
|
163 | 184 | ```
|
164 | 185 |
|
165 | 186 | ### Error Handling
|
166 |
| - |
| 187 | + |
167 | 188 | Here are typical exceptions thrown from the client library:
|
168 | 189 |
|
169 | 190 | * **`DockerApiException`** is thrown when Docker API responds with a non-success result. Subclasses:
|
170 | 191 | * **``DockerContainerNotFoundException``**
|
171 | 192 | * **``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.) |
173 | 194 | * 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.
|
174 | 195 | * **`ArgumentNullException`** is thrown when one of the required parameters are missing/empty.
|
175 | 196 | * 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