createNetwork method
Creates a user-defined Docker network.
The network is labelled with testcontainers metadata via createLabels.
Parameters:
name— network name.options— optional extra body fields merged into the request.
Returns the Docker-assigned network ID.
Implementation
Future<String> createNetwork(
String name, {
Map<String, dynamic>? options,
}) async {
final body = <String, dynamic>{
'Name': name,
'Labels': createLabels('', null),
...?options,
};
final resp = await _request('POST', '/networks/create', body: body);
_throwIfError(resp);
final data = resp.bodyJson as Map<String, dynamic>;
final id = data['Id'] as String?;
if (id == null || id.isEmpty) {
throw StateError(
'Docker API returned a network create response with no Id field. '
'Response body: ${resp.bodyString}',
);
}
return id;
}