exec method

  1. @override
Future<DockerProcess?> exec(
  1. String containerName,
  2. String command,
  3. List<String> args, {
  4. bool? outputAsLines = true,
  5. int? outputLimit,
  6. OutputReadyFunction? stdoutReadyFunction,
  7. OutputReadyFunction? stderrReadyFunction,
  8. OutputReadyType? outputReadyType,
})
override

Executes a command inside containerName with args.

Implementation

@override
Future<DockerProcess?> exec(
  String containerName,
  String command,
  List<String> args, {
  bool? outputAsLines = true,
  int? outputLimit,
  OutputReadyFunction? stdoutReadyFunction,
  OutputReadyFunction? stderrReadyFunction,
  OutputReadyType? outputReadyType,
}) async {
  if (isContainerARunner(containerName)) {
    if (!isContainerRunnerRunning(containerName)) return null;
  } else {
    var running = await isContainerRunning(containerName);
    if (!running) return null;
  }

  var instanceID = DockerProcess.incrementInstanceID();

  outputReadyType ??= DockerHost.resolveOutputReadyType(
      stdoutReadyFunction, stderrReadyFunction);

  stdoutReadyFunction ??= (outputStream, data) => true;
  stderrReadyFunction ??= (outputStream, data) => true;

  var cmdArgs = ['exec', containerName, command, ...args];
  _log.info('docker exec [CMD]>\t$dockerBinaryPath ${cmdArgs.join(' ')}');

  var process = await Process.start(dockerBinaryPath!, cmdArgs);

  var dockerProcess = DockerProcessLocal(
      this,
      instanceID,
      containerName,
      process,
      outputAsLines,
      outputLimit,
      stdoutReadyFunction,
      stderrReadyFunction,
      outputReadyType);

  _processes[instanceID] = dockerProcess;

  var ok = await _initializeAndWaitReady(dockerProcess);
  if (ok) {
    _log.info('Exec[$ok]: $dockerProcess');
  }

  return dockerProcess;
}