mirror of
https://github.com/unraid/webgui.git
synced 2026-04-23 18:48:49 -05:00
Docker code optimization
This commit is contained in:
@@ -15,11 +15,11 @@
|
||||
$user_prefs = '/boot/config/plugins/dockerMan/userprefs.cfg';
|
||||
|
||||
# controlled docker execution
|
||||
function docker($cmd) {
|
||||
return exec("timeout 20 docker $cmd 2>/dev/null");
|
||||
function docker($cmd, &$var=null) {
|
||||
return $var===null ? exec("timeout 20 docker $cmd 2>/dev/null") : exec("timeout 20 docker $cmd 2>/dev/null",$var);
|
||||
}
|
||||
|
||||
exec("timeout 20 docker ps -a --format='{{.Names}}' 2>/dev/null",$all_containers);
|
||||
$all_containers=[]; docker("ps -a --format='{{.Names}}'",$all_containers);
|
||||
|
||||
if (file_exists($user_prefs)) {
|
||||
$prefs = parse_ini_file($user_prefs); $sort = [];
|
||||
|
||||
@@ -33,8 +33,7 @@ $DockerTemplates = new DockerTemplates();
|
||||
|
||||
$echo = function($m){echo "<pre>".print_r($m, true)."</pre>";};
|
||||
|
||||
unset($custom);
|
||||
exec("timeout 20 docker network ls --filter driver='macvlan' --format='{{.Name}}' 2>/dev/null", $custom);
|
||||
$custom=[]; docker("network ls --filter driver='macvlan' --format='{{.Name}}'", $custom);
|
||||
$subnet = ['bridge'=>'', 'host'=>'', 'none'=>''];
|
||||
foreach ($custom as $network) $subnet[$network] = substr(docker("network inspect --format='{{range .IPAM.Config}}{{.Subnet}}, {{end}}' $network"),0,-1);
|
||||
|
||||
@@ -747,7 +746,7 @@ if ($_GET['xmlTemplate']) {
|
||||
echo "<script>var Settings=".json_encode($xml).";</script>";
|
||||
}
|
||||
}
|
||||
exec("timeout 20 docker ps --format='{{.Names}}' 2>/dev/null",$names);
|
||||
$names=[]; docker("ps --format='{{.Names}}'", $names);
|
||||
echo "<script>var UsedPorts=".json_encode(getUsedPorts()).";</script>";
|
||||
echo "<script>var UsedIPs=".json_encode(getUsedIPs()).";</script>";
|
||||
$authoringMode = $dockercfg["DOCKER_AUTHORING_MODE"] == "yes" ? true : false;
|
||||
|
||||
@@ -31,8 +31,8 @@ $dockerManPaths = [
|
||||
if (!isset($eth0) && is_file("$docroot/state/network.ini")) extract(parse_ini_file("$docroot/state/network.ini",true));
|
||||
|
||||
# controlled docker execution
|
||||
function docker($cmd) {
|
||||
return exec("timeout 20 docker $cmd 2>/dev/null");
|
||||
function docker($cmd, &$var=null) {
|
||||
return $var===null ? exec("timeout 20 docker $cmd 2>/dev/null") : exec("timeout 20 docker $cmd 2>/dev/null",$var);
|
||||
}
|
||||
|
||||
# Docker configuration file - guaranteed to exist
|
||||
|
||||
Reference in New Issue
Block a user