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.

46 lines
1.8 KiB

9 years ago
<?php
$container=$_REQUEST['container'];
if (!preg_match(',^[a-f0-9]+$,', $container)) exit(1);
exec('docker inspect '.$container, $res, $ret);
if ($ret!=0) exit(1);
$containers=json_decode(join($res), true);
echo "<table class=\"details docker\"><thead>\n";
echo "<tr><th>Name</th><th>Ports</th><th>Volumes</th><th>Links</th><th>Environments</th><th>Image</th><th>Command</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 ".($p['HostIp']!="0.0.0.0"?$p['HostIp'].":":"").$p['HostPort'].':'.$from.'</li>';
}
}
$ports .= "</ul>";
$volumes = "?";
$links = "<ul>";
if ($c['HostConfig']['Links'])
foreach ($c['HostConfig']['Links'] as $link)
$links.="<li>--link ".preg_replace(',^/?(.*):/?'.$name.'/?(.*)$,', '${1}:${2}', $link)."</li>";
$links .= "</ul>";
$envs = "<ul>";
if ($c['Config']['Env'])
foreach ($c['Config']['Env'] as $env)
if (!preg_match(',^PATH=,', $env))
$envs.="<li>-e ".$env."</li>";
$envs .= "</ul>";
$image = $c['Config']['Image'];
if ($c['Config']['Cmd']) $command = join(" ", $c['Config']['Cmd']);
$status="dead";
if ($c['State']['Dead']) $status = "dead";
elseif ($c['State']['Restarting']) $status = "restarted";
elseif ($c['State']['Paused']) $status = "paused";
elseif ($c['State']['Running']) $status = "running";
echo "<tr class=\"${status}\"><td>docker run -d --name ${name}</td><td>${ports}</td><td>${volumes}</td><td>${links}</td><td>${envs}</td><td>${image}</td><td>${command}</th></tr>\n";
}
echo "</tbody></table>";
echo "<pre>\n".join("\n", $res)."\n</pre>"
?>