buildContainerArgsWithOptions method
ContainerInfosLocal
buildContainerArgsWithOptions(
- String cmd,
- String imageName,
- String? version,
- String containerName,
- DockerRunOptions options, {
- bool addCIDFile = false,
override
Builds the arguments of a Docker cmd (run, create...) with
options. The image is the last argument.
Implementation
@override
ContainerInfosLocal buildContainerArgsWithOptions(
String cmd,
String imageName,
String? version,
String containerName,
DockerRunOptions options, {
bool addCIDFile = false,
}) {
var containerInfos = super.buildContainerArgsWithOptions(
cmd,
imageName,
version,
containerName,
options,
);
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,
);
}