DockerClient class
A thin HTTP client that speaks directly to the Docker Engine API.
By default, DockerClient uses a Unix domain socket (path determined by
dockerSocket) and targets API version v1.41. When DOCKER_HOST
is set to a tcp:// or http:// URL, a plain TCP connection is used
instead.
Instances are stateless (no persistent connection pool) — each method call opens and closes its own socket connection.
Example:
final client = DockerClient();
final id = await client.createContainer('nginx:alpine-slim',
ports: {80: null});
await client.startContainer(id);
final port = await client.port(id, 80);
print('nginx is at http://localhost:$port');
await client.removeContainer(id, force: true);
Constructors
- DockerClient()
- Creates a DockerClient from the environment.
- DockerClient.testOnly()
- Creates a DockerClient with no real socket connection.
Properties
- connectionMode → ConnectionMode
-
Determines the active ConnectionMode for this client.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- host → String
-
Returns the host address used to reach containers.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
archive(
String id, String path) → Future< Uint8List> - Downloads a file or directory from the container's filesystem as a tar archive.
-
bridgeIp(
String id) → Future< String> -
Returns the bridge-network IP address of
id. -
buildImage(
String contextPath, {String? tag, bool noCache = false, String? dockerfile}) → Future< (String, List< Map< )>String, dynamic> > - Builds an image from a local context directory and returns its ID and build logs.
-
connectNetwork(
String networkId, String containerId, {List< String> ? aliases}) → Future<void> -
Connects
containerIdtonetworkId. -
containerDetails(
String id) → Future< Map< String, dynamic> > - Returns the raw inspect JSON for a single container.
-
containerInspectInfo(
String id) → Future< ContainerInspectInfo> -
Returns a strongly-typed inspect model for
id. -
containers(
{bool all = false, Map< String, dynamic> ? filters}) → Future<List< Map< >String, dynamic> > - Lists containers.
-
createContainer(
String image, {List< String> ? command, Map<String, String> env = const {}, String? name, Map<int, int?> ports = const {}, Map<String, ({String bind, String mode})> volumes = const {}, Map<String, String> ? tmpfs, Map<String, String> ? labels, String? network, List<String> ? networkAliases, Map<String, Object?> ? kwargs}) → Future<String> - Creates a container and returns its ID.
-
createNetwork(
String name, {Map< String, dynamic> ? options}) → Future<String> - Creates a user-defined Docker network.
-
decodeChunked(
Uint8List data) → Uint8List -
Exposed for unit testing — delegates to
_decodeChunked. -
execInContainer(
String id, List< String> command) → Future<(int, Uint8List)> -
Runs
commandinsideidand returns its exit code and combined output. -
gatewayIp(
String id) → Future< String> -
Returns the gateway IP address of the bridge network for
id. -
login(
DockerAuthInfo auth) → Future< void> - Authenticates with a Docker registry.
-
logs(
String id) → Future< (Uint8List, Uint8List)> - Fetches the container's stdout and stderr log streams.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parseHttpResponse(
Uint8List bytes) → ({Uint8List body, Map< String, String> headers, int statusCode}) - Exposed for unit testing — parses a raw HTTP/1.0 response byte buffer.
-
port(
String containerId, int port) → Future< int> -
Returns the host port mapped to
portoncontainerId. -
pullImage(
String image) → Future< void> - Pulls an image from a registry.
-
putArchive(
String id, String path, Uint8List tarData) → Future< void> - Uploads a tar archive to the container's filesystem.
-
removeContainer(
String id, {bool force = false, bool removeVolumes = false}) → Future< void> - Removes a container.
-
removeImage(
String imageId, {bool force = true, bool noPrune = false}) → Future< void> - Removes an image from the local image cache.
-
removeNetwork(
String id) → Future< void> - Removes a Docker network.
-
startContainer(
String id) → Future< void> - Starts a previously created container.
-
stopContainer(
String id, {int timeout = 10}) → Future< void> - Stops a running container gracefully.
-
stripDockerLogHeaders(
Uint8List data) → Uint8List -
Exposed for unit testing — delegates to
_stripDockerLogHeaders. -
toString(
) → String -
A string representation of this object.
inherited
-
waitContainer(
String id) → Future< int> - Blocks until the container stops and returns its exit code.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
toDockerKey(
String dartKey) → String - Converts a Dart-style camelCase or snake_case key to the Docker API's PascalCase convention.