mirror of
https://github.com/unraid/webgui.git
synced 2026-04-23 02:31:45 -05:00
Docker: improved processing of custom network types
This commit is contained in:
@@ -31,7 +31,13 @@ $DockerTemplates = new DockerTemplates();
|
||||
|
||||
$custom = array_merge(DockerUtil::docker("network ls --filter driver='bridge' --format='{{.Name}}'|grep -v '^bridge$'",true),DockerUtil::docker("network ls --filter driver='macvlan' --format='{{.Name}}'",true));
|
||||
$subnet = ['bridge'=>'', 'host'=>'', 'none'=>''];
|
||||
$driver = [];
|
||||
|
||||
foreach ($custom as $network) $subnet[$network] = substr(DockerUtil::docker("network inspect --format='{{range .IPAM.Config}}{{.Subnet}}, {{end}}' $network"),0,-1);
|
||||
foreach (DockerUtil::docker("network ls --format='{{.Name}}|{{.Driver}}'",true) as $network) {
|
||||
list($name,$type) = explode('|',$network);
|
||||
$driver[$name] = $type;
|
||||
}
|
||||
|
||||
function stopContainer($name) {
|
||||
global $DockerClient;
|
||||
@@ -366,8 +372,7 @@ function xmlSecurity(&$template) {
|
||||
}
|
||||
|
||||
function xmlToCommand($xml, $create_paths=false) {
|
||||
global $var;
|
||||
global $docroot;
|
||||
global $docroot, $var, $driver;
|
||||
$xml = xmlToVar($xml);
|
||||
$cmdName = strlen($xml['Name']) ? '--name='.escapeshellarg($xml['Name']) : '';
|
||||
$cmdPrivileged = strtolower($xml['Privileged'])=='true' ? '--privileged=true' : '';
|
||||
@@ -396,16 +401,15 @@ function xmlToCommand($xml, $create_paths=false) {
|
||||
@chgrp($hostConfig, 100);
|
||||
}
|
||||
} elseif ($confType == 'port') {
|
||||
$net = strtolower($xml['Network']);
|
||||
$type = $driver[$xml['Network']];
|
||||
// Export ports as variable if network is set to host or macvlan
|
||||
if (preg_match('/^(host|eth[0-9]|br[0-9]|bond[0-9])/',$net) || strpos($net,'bridge')!==false) {
|
||||
if ($type=='host' || $type=='macvlan') {
|
||||
$Variables[] = strtoupper(escapeshellarg($Mode.'_PORT_'.$containerConfig).'='.escapeshellarg($hostConfig));
|
||||
// No export of ports if network is set to none
|
||||
} elseif ($net == 'none') {
|
||||
} elseif ($type == 'bridge') {
|
||||
// Export ports as port if network is set to (custom) bridge
|
||||
} else {
|
||||
$Ports[] = escapeshellarg($hostConfig.':'.$containerConfig.'/'.$Mode);
|
||||
}
|
||||
// No export of ports if network is set to none
|
||||
} elseif ($confType == "variable") {
|
||||
$Variables[] = escapeshellarg($containerConfig).'='.escapeshellarg($hostConfig);
|
||||
} elseif ($confType == "device") {
|
||||
|
||||
Reference in New Issue
Block a user