createContainer method
Future<ContainerInfos?>
createContainer(
- String containerName,
- String imageName, {
- String? version,
- List<
String> ? ports, - String? network,
- String? hostname,
- Map<
String, String> ? environment, - Map<
String, String> ? volumes, - bool cleanContainer = false,
- String? healthCmd,
- Duration? healthInterval,
- int? healthRetries,
- Duration? healthStartPeriod,
- Duration? healthTimeout,
- String? restart,
override
Creates a Docker containers with image
and optional version
.
Implementation
@override
Future<ContainerInfos?> createContainer(
String containerName,
String imageName, {
String? version,
List<String>? ports,
String? network,
String? hostname,
Map<String, String>? environment,
Map<String, String>? volumes,
bool cleanContainer = false,
String? healthCmd,
Duration? healthInterval,
int? healthRetries,
Duration? healthStartPeriod,
Duration? healthTimeout,
String? restart,
}) async {
if (isEmptyString(containerName, trim: true)) {
return null;
}
var containerInfos = buildContainerArgs(
'create',
imageName,
version,
containerName,
ports,
network,
hostname,
environment,
volumes,
cleanContainer,
healthCmd,
healthInterval,
healthRetries,
healthStartPeriod,
healthTimeout,
restart,
addCIDFile: true,
);
var cmdArgs = containerInfos.args!;
_log.info('create[CMD]>\t$dockerBinaryPath ${cmdArgs.join(' ')}');
var process = await Process.start(dockerBinaryPath!, cmdArgs);
var exitCode = await process.exitCode;
if (exitCode != 0) return null;
containerInfos.id = await _readContainerID(
containerInfos.containerName, containerInfos.idFile, process);
return exitCode == 0 ? containerInfos : null;
}