Class DockerClient
Implements a client that can submit commands to a Docker engine via the Docker Remote API.
Namespace: Neon.Docker
Assembly: Neon.Docker.dll
Syntax
public class DockerClient
Constructors
DockerClient(DockerSettings)
Constructor.
Declaration
public DockerClient(DockerSettings settings)
Parameters
Type | Name | Description |
---|---|---|
DockerSettings | settings | The settings |
Properties
ApiVersion
Returns the version of the Docker Remote API implemented by this class.
Declaration
public Version ApiVersion { get; }
Property Value
Type | Description |
---|---|
Version |
JsonClient
Returns the underlying JsonClient.
Declaration
public JsonClient JsonClient { get; }
Property Value
Type | Description |
---|---|
JsonClient |
Settings
Returns the DockerSettings.
Declaration
public DockerSettings Settings { get; }
Property Value
Type | Description |
---|---|
DockerSettings |
Methods
Dispose()
Releases all resources associated with the instance.
Declaration
public void Dispose()
Dispose(bool)
Releases all associated resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Pass |
NetworkCreateAsync(DockerNetwork, CancellationToken)
Creates a Docker network.
Declaration
public Task<NetworkCreateResponse> NetworkCreateAsync(DockerNetwork network, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
DockerNetwork | network | The network details. |
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task<NetworkCreateResponse> |
NetworkInspect(string, CancellationToken)
Returns details about a specific Docker network.
Declaration
public Task<DockerNetwork> NetworkInspect(string nameOrId, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | nameOrId | The network name or ID. |
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task<DockerNetwork> | A DockerNetwork instance. |
NetworkListAsync(CancellationToken)
Lists the networks managed by the Docker engine.
Declaration
public Task<List<DockerNetwork>> NetworkListAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task<List<DockerNetwork>> | A list of DockerNetwork instances. |
NetworkRemove(string, CancellationToken)
Removes a Docker network.
Declaration
public Task NetworkRemove(string nameOrId, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | nameOrId | The network name or ID. |
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task | The tracking Task. |
NodeListAsync(CancellationToken)
Lists the swarm nodes.
Declaration
public Task<List<DockerNode>> NodeListAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task<List<DockerNode>> | The node list. |
ParseObject<T>(JObject)
Parses a JObject value into an instance of the specified type by converting it to JSON and then parsing that.
Declaration
public static T ParseObject<T>(JObject value) where T : class, new()
Parameters
Type | Name | Description |
---|---|---|
JObject | value | The input dynamic. |
Returns
Type | Description |
---|---|
T | The parsed value. |
Type Parameters
Name | Description |
---|---|
T | The desired output type. |
PingAsync(CancellationToken)
Ping the remote Docker engine to verify that it's ready.
Declaration
public Task<bool> PingAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task<bool> |
|
Remarks
note
This method does not use a IRetryPolicy.
ServiceListAsync(CancellationToken)
Lists the services deployed to a Docker Swarm.
Declaration
public Task<ServiceListResponse> ServiceListAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task<ServiceListResponse> |
VolumeCreate(string, string, CancellationToken, params KeyValuePair<string, string>[])
Creates a Docker volume.
Declaration
public Task<DockerVolume> VolumeCreate(string name = null, string driver = null, CancellationToken cancellationToken = default, params KeyValuePair<string, string>[] driverOpts)
Parameters
Type | Name | Description |
---|---|---|
string | name | The optional volume name (Docker will generate a name if this is not specified). |
string | driver | The optional volume driver name (defaults to |
CancellationToken | cancellationToken | Optional cancellation token. |
KeyValuePair<string, string>[] | driverOpts | The custom driver options. |
Returns
Type | Description |
---|---|
Task<DockerVolume> | The docker volume. |
VolumeInspect(string, CancellationToken)
Returns information about a Docker volume.
Declaration
public Task<DockerVolume> VolumeInspect(string nameOrId, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | nameOrId | The volume name or ID. |
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task<DockerVolume> | The DockerVolume. |
VolumeListAsync(CancellationToken)
Lists the volumes managed by the Docker engine.
Declaration
public Task<VolumeListResponse> VolumeListAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task<VolumeListResponse> |
VolumeRemove(string, CancellationToken)
Removes a Docker volume.
Declaration
public Task VolumeRemove(string nameOrId, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | nameOrId | The volume name or ID. |
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task | The tracking Task. |
WaitUntilReadyAsync(TimeSpan?, CancellationToken)
Waits for the Docker engine or Swarm manager to be ready to accept requests.
Declaration
public Task WaitUntilReadyAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan? | timeout | The maximum timne to wait (defaults to 120 seconds). |
CancellationToken | cancellationToken | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task | The tracking Task. |
Remarks
The Swarm Manager can return unexpected HTTP response codes when it is not ready to accept requests. For example, a request to /volumes may return a 404: Not Found response rather than the 503: Service Unavailable that one would expect. The server can return this even when PingAsync(CancellationToken) return successfully.
This method attempts to ensure that the server is really ready.