buildContainerArgs method

  1. @override
ContainerInfosLocal buildContainerArgs(
  1. String cmd,
  2. String imageName,
  3. String? version,
  4. String containerName,
  5. List<String>? ports,
  6. String? network,
  7. String? hostname,
  8. Map<String, String>? environment,
  9. Map<String, String>? volumes,
  10. bool cleanContainer,
  11. String? healthCmd,
  12. Duration? healthInterval,
  13. int? healthRetries,
  14. Duration? healthStartPeriod,
  15. Duration? healthTimeout,
  16. String? restart, {
  17. bool addCIDFile = false,
})
override

Implementation

@override
ContainerInfosLocal buildContainerArgs(
  String cmd,
  String imageName,
  String? version,
  String containerName,
  List<String>? ports,
  String? network,
  String? hostname,
  Map<String, String>? environment,
  Map<String, String>? volumes,
  bool cleanContainer,
  String? healthCmd,
  Duration? healthInterval,
  int? healthRetries,
  Duration? healthStartPeriod,
  Duration? healthTimeout,
  String? restart, {
  bool addCIDFile = false,
}) {
  var containerInfos = super.buildContainerArgs(
    cmd,
    imageName,
    version,
    containerName,
    ports,
    network,
    hostname,
    environment,
    volumes,
    cleanContainer,
    healthCmd,
    healthInterval,
    healthRetries,
    healthStartPeriod,
    healthTimeout,
    restart,
  );

  var args = containerInfos.args!;
  // Last parameter is the image.
  // Remove to append more parameters, then add it in the end:
  args.removeLast();

  if (containerInfos.containerNetwork != null) {
    var networkHostsIPs =
        getNetworkRunnersHostnamesAndIPs(containerInfos.containerNetwork);

    for (var networkContainerName in networkHostsIPs.keys) {
      if (networkContainerName == containerName) continue;

      var hostMaps = networkHostsIPs[networkContainerName]!;

      for (var host in hostMaps.keys) {
        var ip = hostMaps[host];
        args.add('--add-host');
        args.add('$host:$ip');
      }
    }
  }

  File? idFile;
  if (addCIDFile) {
    idFile = _createTemporaryFile('cidfile');
    args.add('--cidfile');
    args.add(idFile.path);
  }

  args.add(containerInfos.image!);

  return ContainerInfosLocal(
    containerInfos.containerName,
    containerInfos.image,
    idFile,
    containerInfos.ports,
    containerInfos.containerNetwork,
    containerInfos.containerHostname,
    containerInfos.args,
  );
}