Servicedock: Webgui for Docker Swarm. Manage Docker Swarm a a Service.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

39 lines
1.8 KiB

<?php
exec("docker ps -aq", $res, $ret);
if ($ret!=0) exit(1);
exec("docker inspect ".join(" ", $res), $res2, $ret);
if ($ret!=0) exit(1);
$containers=json_decode(join($res2), true);
echo "<table class=\"manage docker\"><thead>\n";
echo "<tr><th>Name</th><th>Ports</th><th>Links</th><th>Image</th><th>Actions</th></tr>\n";
echo "</thead><tbody>";
foreach ($containers as $c) {
$name = preg_replace(',^/,', '', $c['Name']);
$ports = "<ul>";
if ($c['NetworkSettings']['Ports'])
foreach ($c['NetworkSettings']['Ports'] as $from => $to) {
if ($to)
foreach ($to as $p) {
if (isset($p['HostPort']))
$ports.="<li>".($p['HostIp']!="0.0.0.0"?$p['HostIp'].":":"").$p['HostPort'].':'.$from.'</li>';
}
}
$ports .= "</ul>";
$links = "<ul>";
if ($c['HostConfig']['Links'])
foreach ($c['HostConfig']['Links'] as $link)
$links.="<li>".preg_replace(',^/?(.*):/?'.$name.'/?(.*)$,', '${1}:${2}', $link)."</li>";
$links .= "</ul>";
$image = $c['Config']['Image'];
if ($c['State']['Dead']) {$status = "dead"; $actions=Array("start", "rm");}
elseif ($c['State']['Restarting']) {$status = "restarted"; $actions=Array();}
elseif ($c['State']['Paused']) {$status = "paused"; $actions=Array("unpause", "rm");}
elseif ($c['State']['Running']) {$status = "running"; $actions=Array("pause", "stop");}
else {$status="dead"; $actions=Array("start", "remove");}
$action="";
foreach($actions as $a)
$action.='<a class="toolbutton" href="javascript:action('."'".$c['Id']."', '".$a."'".');">'.$a.'</a>';
echo '<tr class="'.$status.'"><td><a href="javascript:details('."'".$c['Id']."'",')">'.$name.'</a></td><td>'.$ports.'</td><td>'.$volumes.'</td><td>'.$links.'</td><td>'.$envs.'</td><td>'.$image.'</td><td>'.$command.'</td><td><td class="buttongroup">'.$action.'</tr>'."\n";
}
echo "</tbody></table>";
?>