create method
The network's id, creating it on the daemon of docker at the first
call.
A creation that fails is not remembered: who asked gets the daemon's error, and the next call tries again. One refusal of the daemon would otherwise fail every later container of the network with it.
Implementation
Future<String> create(DockerClient docker) {
if (_id case final known?) {
return known;
}
late final Future<String> creating;
Future<String> run() async {
try {
return await docker.createNetwork(
name,
labels: ContainerRuntime.instance.labels,
);
} on Object {
// Unless the network was closed and asked for again meanwhile.
if (identical(_id, creating)) {
_id = null;
}
rethrow;
}
}
_docker = docker;
return _id = creating = run();
}