run method
Future<DockerRunner>
run(
- String image, {
- String? version,
- List<
String> ? imageArgs, - String? containerName,
- List<
String> ? ports, - String? network,
- String? hostname,
- Map<
String, String> ? environment, - Map<
String, String> ? volumes, - bool cleanContainer = true,
- String? healthCmd,
- Duration? healthInterval,
- int? healthRetries,
- Duration? healthStartPeriod,
- Duration? healthTimeout,
- String? restart,
- bool? outputAsLines = true,
- int? outputLimit,
- OutputReadyFunction? stdoutReadyFunction,
- OutputReadyFunction? stderrReadyFunction,
- OutputReadyType? outputReadyType,
override
Runs a Docker containers with image
and optional version
.
Implementation
@override
Future<DockerRunner> run(
String image, {
String? version,
List<String>? imageArgs,
String? containerName,
List<String>? ports,
String? network,
String? hostname,
Map<String, String>? environment,
Map<String, String>? volumes,
bool cleanContainer = true,
String? healthCmd,
Duration? healthInterval,
int? healthRetries,
Duration? healthStartPeriod,
Duration? healthTimeout,
String? restart,
bool? outputAsLines = true,
int? outputLimit,
OutputReadyFunction? stdoutReadyFunction,
OutputReadyFunction? stderrReadyFunction,
OutputReadyType? outputReadyType,
}) async {
outputAsLines ??= true;
outputReadyType ??= DockerHost.resolveOutputReadyType(
stdoutReadyFunction, stderrReadyFunction);
stdoutReadyFunction ??= (outputStream, data) => true;
stderrReadyFunction ??= (outputStream, data) => true;
var instanceID = DockerProcess.incrementInstanceID();
if (isEmptyString(containerName, trim: true)) {
containerName = 'docker_commander-$session-$instanceID';
}
var containerInfos = buildContainerArgs(
'run',
image,
version,
containerName!,
ports,
network,
hostname,
environment,
volumes,
cleanContainer,
healthCmd,
healthInterval,
healthRetries,
healthStartPeriod,
healthTimeout,
restart,
addCIDFile: true,
);
var cmdArgs = containerInfos.args!;
if (imageArgs != null) {
cmdArgs.addAll(imageArgs);
}
_log.info('run[CMD]>\t$dockerBinaryPath ${cmdArgs.join(' ')}');
var process = await Process.start(dockerBinaryPath!, cmdArgs);
var containerNetwork = containerInfos.containerNetwork;
var runner = DockerRunnerLocal(
this,
instanceID,
containerInfos.containerName,
containerInfos.image,
process,
containerInfos.idFile,
containerInfos.ports,
containerNetwork,
containerInfos.containerHostname,
outputAsLines,
outputLimit,
stdoutReadyFunction,
stderrReadyFunction,
outputReadyType);
_runners[instanceID] = runner;
_processes[instanceID] = runner;
var ok = await _initializeAndWaitReady(runner, () async {
if (containerNetwork != null) {
await _configureContainerNetwork(containerNetwork, runner);
}
});
if (ok) {
_log.info('Runner[$ok]: $runner');
}
return runner;
}