Skip to content

Commit 7265ce7

Browse files
committed
docs: Update README.md
1 parent 140710f commit 7265ce7

File tree

1 file changed

+58
-70
lines changed

1 file changed

+58
-70
lines changed

README.md

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,40 @@
1-
[![NuGet](https://img.shields.io/nuget/v/Docker.DotNet.Enhanced.svg)](https://www.nuget.org/packages/Docker.DotNet.Enhanced)
2-
31
> [!IMPORTANT]
42
> Unfortunately, there has been no further development or bug fixes in [Docker.DotNet](https://github.com/dotnet/Docker.DotNet/tree/aacf3c26131f582ca8acc34084663a4b79e28d38) for some time now, and the repository appears inactive. Reaching the current maintainer is challenging. I understand that priorities shift, and maintaining an open-source project is time-consuming and exhausting. As maintainers, we often cannot dedicate the necessary time. Over the past months—and even years—I have frequently offered my help.
53
>
64
> Docker.DotNet is an important upstream dependency for Testcontainers for .NET and many other developers. It would be unfortunate for this valuable work not to continue. Therefore, I have decided to fork the repository to focus on essential fixes, improvements, and updates for the Docker Engine API. I am also accepting further contributions and remaining PRs from the upstream repository.
75
86
# .NET Client for Docker Remote API
97

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

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

14-
## Versioning
15-
16-
Version of this package uses [SemVer](https://semver.org/) format: `MAJOR.MINOR.PATCH`. `MINOR` segment indicates
17-
the [Docker Remote API][docker-remote-api] version support. For instance `v2.124.0` of this library supports
18-
[Docker Remote API][docker-remote-api] `v1.24`. This does not guarantee backwards compatibility as [Docker Remote API][docker-remote-api] does not guarantee that either.
19-
20-
`MAJOR` is reserved for major breaking changes we make to the library itself such as how
21-
the calls are made or how authentication is made. `PATCH` is just for incremental bug fixes
22-
or non-breaking feature additions.
23-
2412
## Installation
2513

2614
[![NuGet latest release](https://img.shields.io/nuget/v/Docker.DotNet.Enhanced.svg)](https://www.nuget.org/packages/Docker.DotNet.Enhanced)
2715

2816
You can add this library to your project using [NuGet][nuget].
2917

3018
**Package Manager Console**
31-
Run the following command in the “Package Manager Console”:
19+
20+
Run the following command in the "Package Manager Console":
3221

3322
> PM> Install-Package Docker.DotNet.Enhanced
3423
3524
**Visual Studio**
36-
Right click to your project in Visual Studio, choose “Manage NuGet Packages” and search for ‘Docker.DotNet’ and click ‘Install’.
37-
([see NuGet Gallery][nuget-gallery].)
25+
26+
Right click to your project in Visual Studio, choose "Manage NuGet Packages" and search for "Docker.DotNet" and click "Install".
27+
(see [NuGet Gallery][nuget-gallery].)
3828

3929
**.NET Core Command Line Interface**
30+
4031
Run the following command from your favorite shell or terminal:
4132

4233
> dotnet add package Docker.DotNet.Enhanced
4334
4435
**Development Builds**
4536

46-
[![CI](https://github.com/testcontainers/Docker.DotNet/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/testcontainers/Docker.DotNet/actions/workflows/ci.yml)
37+
[![CI](https://github.com/testcontainers/Docker.DotNet/actions/workflows/ci.yml/badge.svg)](https://github.com/testcontainers/Docker.DotNet/actions/workflows/ci.yml)
4738

4839
## Usage
4940

@@ -53,14 +44,15 @@ You can initialize the client like the following:
5344
using Docker.DotNet;
5445
DockerClient client = new DockerClientConfiguration(
5546
new Uri("http://ubuntu-docker.cloudapp.net:4243"))
56-
.CreateClient();
47+
.CreateClient();
5748
```
58-
or to connect to your local [Docker for Windows](https://docs.docker.com/docker-for-windows/) daemon using named pipes or your local [Docker for Mac](https://docs.docker.com/docker-for-mac/) daemon using Unix sockets:
49+
50+
or to connect to your local [Docker Desktop on Windows](https://docs.docker.com/desktop/setup/install/windows-install/) daemon using named pipes or your local [Docker Desktop on Mac](https://docs.docker.com/desktop/setup/install/mac-install/) daemon using Unix sockets:
5951

6052
```csharp
6153
using Docker.DotNet;
6254
DockerClient client = new DockerClientConfiguration()
63-
.CreateClient();
55+
.CreateClient();
6456
```
6557

6658
For a custom endpoint, you can also pass a named pipe or a Unix socket to the `DockerClientConfiguration` constructor. For example:
@@ -70,27 +62,29 @@ For a custom endpoint, you can also pass a named pipe or a Unix socket to the `D
7062
using Docker.DotNet;
7163
DockerClient client = new DockerClientConfiguration(
7264
new Uri("npipe://./pipe/docker_engine"))
73-
.CreateClient();
65+
.CreateClient();
66+
7467
// Default Docker Engine on Linux
7568
using Docker.DotNet;
7669
DockerClient client = new DockerClientConfiguration(
7770
new Uri("unix:///var/run/docker.sock"))
78-
.CreateClient();
71+
.CreateClient();
7972
```
8073

8174
#### Example: List containers
8275

8376
```csharp
8477
IList<ContainerListResponse> containers = await client.Containers.ListContainersAsync(
85-
new ContainersListParameters(){
78+
new ContainersListParameters
79+
{
8680
Limit = 10,
8781
});
8882
```
8983

9084
#### Example: Create an image by pulling from Docker Registry
9185

9286
The code below pulls `fedora/memcached` image to your Docker instance using your Docker Hub account. You can
93-
anonymously download the image as well by passing `null` instead of AuthConfig object:
87+
anonymously download the image as well by passing `null` instead of `AuthConfig` object:
9488

9589
```csharp
9690
await client.Images.CreateImageAsync(
@@ -108,16 +102,16 @@ await client.Images.CreateImageAsync(
108102
new Progress<JSONMessage>());
109103
```
110104

111-
112105
#### Example: Create a container
113106

114-
The following code will create a new container of the previously fetched image.
107+
The following code will create a new container of the previously fetched image:
115108

116109
```csharp
117-
await client.Containers.CreateContainerAsync(new CreateContainerParameters()
110+
await client.Containers.CreateContainerAsync(
111+
new CreateContainerParameters
118112
{
119113
Image = "fedora/memcached",
120-
HostConfig = new HostConfig()
114+
HostConfig = new HostConfig
121115
{
122116
DNS = new[] { "8.8.8.8", "8.8.4.4" }
123117
}
@@ -126,24 +120,23 @@ await client.Containers.CreateContainerAsync(new CreateContainerParameters()
126120

127121
#### Example: Start a container
128122

129-
The following code will start the created container.
123+
The following code will start the created container:
130124

131125
```csharp
132126
await client.Containers.StartContainerAsync(
133127
"39e3317fd258",
134-
new ContainerStartParameters()
135-
);
128+
new ContainerStartParameters());
136129
```
137130

138131
#### Example: Stop a container
139132

140133
The following code will stop a running container.
141134

142-
*Note: `WaitBeforeKillSeconds` field is of type `uint?` which means optional. This code will wait 30 seconds before
143-
killing it. If you like to cancel the waiting, you can use the CancellationToken parameter.*
135+
**Note**: `WaitBeforeKillSeconds` field is of type `uint?` which means optional. This code will wait 30 seconds before
136+
killing it. If you like to cancel the waiting, you can use the cancellation token parameter.
144137

145138
```csharp
146-
var stopped = await client.Containers.StopContainerAsync(
139+
bool hasStopped = await client.Containers.StopContainerAsync(
147140
"39e3317fd258",
148141
new ContainerStopParameters
149142
{
@@ -154,9 +147,9 @@ var stopped = await client.Containers.StopContainerAsync(
154147

155148
#### Example: Dealing with Stream responses
156149

157-
Some Docker API endpoints are designed to return stream responses. For example
158-
[Monitoring Docker events](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/monitor-docker-s-events)
159-
continuously streams the status in a format like :
150+
Some Docker Engine API endpoints are designed to return stream responses. For example
151+
[Monitor events](https://docs.docker.com/reference/api/engine/version/v1.49/#tag/System/operation/SystemEvents)
152+
continuously streams the status in a format like:
160153

161154
```json
162155
{"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
@@ -169,55 +162,48 @@ continuously streams the status in a format like :
169162
To obtain this stream you can use:
170163

171164
```csharp
172-
CancellationTokenSource cancellation = new CancellationTokenSource();
173-
Stream stream = await client.System.MonitorEventsAsync(new ContainerEventsParameters(), new Progress<JSONMessage>(), cancellation.Token);
174-
// Initialize a StreamReader...
165+
Stream stream = await client.System.MonitorEventsAsync(
166+
new ContainerEventsParameters(),
167+
new Progress<JSONMessage>(),
168+
CancellationToken.None);
175169
```
176170

177-
You can cancel streaming using the CancellationToken. On the other hand, if you wish to continuously stream, you can simply pass `CancellationToken.None`.
171+
You can cancel streaming using the cancellation token. Or, if you wish to continuously stream, you can simply use `CancellationToken.None`.
178172

179-
#### Example: HTTPS Authentication to Docker
173+
#### Example: HTTPS authentication to Docker
180174

181-
If you are [running Docker with TLS (HTTPS)][docker-tls], you can authenticate to the Docker instance using the [**`Docker.DotNet.X509`**][Docker.DotNet.X509] package. You can get this package from NuGet or by running the following command in the Package Manager Console:
175+
If you are [running Docker with TLS (HTTPS)][docker-tls], you can authenticate to the Docker instance using the [**`Docker.DotNet.Enhanced.X509`**][Docker.DotNet.X509] package. You can get this package from NuGet or by running the following command in the "Package Manager Console":
182176

183-
PM> Install-Package Docker.DotNet.X509
177+
PM> Install-Package Docker.DotNet.Enhanced.X509
184178

185-
Once you add `Docker.DotNet.X509` to your project, use `CertificateCredentials` type:
179+
Once you add `Docker.DotNet.Enhanced.X509` to your project, use the `CertificateCredentials` type:
186180

187181
```csharp
188-
var credentials = new CertificateCredentials (new X509Certificate2 ("CertFile", "Password"));
182+
var credentials = new CertificateCredentials(new X509Certificate2("CertFile", "Password"));
189183
var config = new DockerClientConfiguration("http://ubuntu-docker.cloudapp.net:4243", credentials);
190184
DockerClient client = config.CreateClient();
191185
```
192186

193187
If you don't want to authenticate you can omit the `credentials` parameter, which defaults to an `AnonymousCredentials` instance.
194188

195-
The `CertFile` in the example above should be a .pfx file (PKCS12 format), if you have .pem formatted certificates which Docker normally uses you can either convert it programmatically or use `openssl` tool to generate a .pfx:
189+
The `CertFile` in the example above should be a PFX file (PKCS12 format), if you have PEM formatted certificates which Docker normally uses you can either convert it programmatically or use `openssl` tool to generate a PFX:
196190

197191
openssl pkcs12 -export -inkey key.pem -in cert.pem -out key.pfx
198192

199-
(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:
200-
```c#
201-
//
202-
// There are two options to do this.
203-
//
204-
205-
// You can do this globally for all certificates:
206-
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
207-
208-
// Or you can do this on a credential by credential basis:
209-
var creds = new CertificateCredentials(...);
210-
creds.ServerCertificateValidationCallback += (o, c, ch, er) => true;
193+
(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:
211194

195+
```csharp
196+
var credentials = new CertificateCredentials(new X509Certificate2("CertFile", "Password"));
197+
credentials.ServerCertificateValidationCallback = (o, c, ch, er) => true;
212198
```
213199

214-
#### Example: Basic HTTP Authentication to Docker
200+
#### Example: HTTP authentication
215201

216-
If the Docker instance is secured with Basic HTTP Authentication, you can use the [**`Docker.DotNet.BasicAuth`**][Docker.DotNet.BasicAuth] package. Get this package from NuGet or by running the following command in the Package Manager Console:
202+
If the Docker instance is secured with "Basic" HTTP authentication, you can use the [**`Docker.DotNet.Enhanced.BasicAuth`**][Docker.DotNet.BasicAuth] package. Get this package from NuGet or by running the following command in the "Package Manager Console":
217203

218-
PM> Install-Package Docker.DotNet.BasicAuth
204+
PM> Install-Package Docker.DotNet.Enhanced.BasicAuth
219205

220-
Once you added `Docker.DotNet.BasicAuth` to your project, use `BasicAuthCredentials` type:
206+
Once you added `Docker.DotNet.Enhanced.BasicAuth` to your project, use `BasicAuthCredentials` type:
221207

222208
```csharp
223209
var credentials = new BasicAuthCredentials ("YOUR_USERNAME", "YOUR_PASSWORD");
@@ -229,18 +215,19 @@ DockerClient client = config.CreateClient();
229215

230216
#### Example: Specifying Remote API Version
231217

232-
By default this client does not specify version number to the API for the requests it makes. However, if you would like to make use of versioning feature of Docker Remote API You can initialize the client like the following.
218+
By default this client does not specify version number to the API for the requests it makes.
219+
However, if you would like to make use of versioning feature of Docker Remote API You can initialize the client like the following.
233220

234221
```csharp
235222
var config = new DockerClientConfiguration(...);
236-
DockerClient client = config.CreateClient(new Version(1, 16));
223+
DockerClient client = config.CreateClient(new Version(1, 49));
237224
```
238225

239226
### Error Handling
240227

241228
Here are typical exceptions thrown from the client library:
242229

243-
* **`DockerApiException`** is thrown when Docker API responds with a non-success result. Subclasses:
230+
* **`DockerApiException`** is thrown when Docker Engine API responds with a non-success result. Subclasses:
244231
* **``DockerContainerNotFoundException``**
245232
* **``DockerImageNotFoundException``**
246233
* **`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.)
@@ -252,12 +239,13 @@ Here are typical exceptions thrown from the client library:
252239

253240
Docker.DotNet is licensed under the [MIT](LICENSE) license.
254241

255-
---------------
256-
Copyright (c) .NET Foundation and Contributors
257-
Copyright (c) Andre Hofmeister
242+
---
243+
244+
- Copyright (c) .NET Foundation and Contributors
245+
- Copyright (c) Andre Hofmeister
258246

259247
[docker-remote-api]: https://docs.docker.com/engine/reference/api/docker_remote_api/
260-
[docker-tls]: https://docs.docker.com/articles/https/
248+
[docker-tls]: https://docs.docker.com/engine/security/protect-access/
261249
[nuget]: http://www.nuget.org
262250
[nuget-gallery]: https://www.nuget.org/packages/Docker.DotNet.Enhanced/
263251
[Docker.DotNet.X509]: https://www.nuget.org/packages/Docker.DotNet.Enhanced.X509/

0 commit comments

Comments
 (0)