run method
LogStream<ContainerRunResult>
run(
{ - required String image,
- String? command,
- Map<String, String> env = const {},
- String? mountPath,
- String? mountSubpath,
- String? role,
- String? participantName,
- Map<int, int> ports = const {},
- Map<String, String>? variables,
- List<DockerSecret> credentials = const [],
- bool detach = true,
})
Implementation
LogStream<ContainerRunResult> run({
required String image,
String? command,
Map<String, String> env = const {},
String? mountPath,
String? mountSubpath,
String? role,
String? participantName,
Map<int, int> ports = const {},
Map<String, String>? variables,
List<DockerSecret> credentials = const [],
bool detach = true,
}) {
final requestId = Uuid().v4().toString();
final controller = StreamController<String>();
final completer = Completer<ContainerRunResult>();
final progress = StreamController<LogProgress>();
final stream = LogStream<ContainerRunResult>._(completer, controller.stream, progress.stream, () async {
await room.sendRequest('containers.stop_container', {'request_id': requestId});
});
_loggers[requestId] = controller;
_progress[requestId] = progress;
final req = _RunRequest(
requestId: requestId,
image: image,
command: command,
env: env,
mountPath: mountPath,
mountSubpath: mountSubpath,
role: role,
participantName: participantName,
ports: ports,
credentials: credentials,
detach: detach,
variables: variables,
);
room
.sendRequest("containers.run", req.toJson())
.then(
(result) {
final json = result as JsonResponse;
controller.close();
completer.complete(
ContainerRunResult(status: json.json["status"], logs: (result.json["logs"] as List).map((l) => l as String).toList()),
);
_loggers.remove(requestId);
},
onError: (error) {
controller.close();
completer.completeError(error);
_loggers.remove(requestId);
},
);
return stream;
}