exec method
Runs command in the running container id and waits for it:
Testcontainers' execInContainer.
Implementation
Future<DockerExecResult> exec(String id, List<String> command) async {
final created = await _json(
await _send(
'POST',
'/containers/$id/exec',
json: {
'AttachStdout': true,
'AttachStderr': true,
'Cmd': command,
},
),
);
final execId = '${created['Id']}';
final out = <String>[];
final err = <String>[];
final response = await _send(
'POST',
'/exec/$execId/start',
json: {'Detach': false, 'Tty': false},
);
await for (final line in _demultiplex(response)) {
(line.stream == DockerStream.stdout ? out : err).add(line.text);
}
final info = await _json(await _send('GET', '/exec/$execId/json'));
return DockerExecResult(
exitCode: (info['ExitCode'] as num?)?.toInt() ?? -1,
stdout: out.join('\n'),
stderr: err.join('\n'),
);
}