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 {
ports = DockerHost.normalizeMappedPorts(ports);
var response = await _httpClient.getJSON('create', parameters: {
'image': imageName,
if (version != null) 'version': version,
'name': containerName,
if (ports != null) 'ports': ports.join(','),
if (network != null) 'network': network,
if (hostname != null) 'hostname': hostname,
if (environment != null) 'environment': encodeQueryString(environment),
if (volumes != null) 'volumes': encodeQueryString(volumes),
'cleanContainer': '$cleanContainer',
if (healthCmd != null) 'healthCmd': healthCmd,
if (healthInterval != null)
'healthInterval': '${healthInterval.inMilliseconds}',
if (healthRetries != null) 'healthRetries': '$healthRetries',
if (healthStartPeriod != null)
'healthStartPeriod': '${healthStartPeriod.inMilliseconds}',
if (healthTimeout != null)
'healthTimeout': '${healthTimeout.inMilliseconds}',
if (restart != null) 'restart': restart,
}) as Map?;
if (response == null) return null;
containerName = response['containerName'] as String;
var id = response['id'] as String?;
var image = response['image'] as String?;
var portsList = response['ports'] as List?;
network = response['network'] as String?;
hostname = response['hostname'] as String?;
ports = portsList?.cast<String>().toList();
return ContainerInfos(containerName, id, image, ports, network, hostname);
}