在自家群晖nas中搭建了导航页,但是总是不方便,每次添加的docker应用都要手动去添加导航信息,就索性直接写个插件(点我查看插件代码);容器启动后是彩色图标,容器关闭后是灰色图标;
需要先加载两个composer 包;
composer require clue/docker-react:^1.4
composer require react/async:3.0文章来源:https://www.toymoban.com/news/detail-505326.html
代码如下文章来源地址https://www.toymoban.com/news/detail-505326.html
<?php
require __DIR__ . '/../vendor/autoload.php';
class Plugin_Lists implements PluginInterface
{
public function list_before($val = '1')
{
$this->data();
}
public function list_after($val = '1')
{
// $this->data();
}
private function data()
{
$client = new Clue\React\Docker\Client(null, 'http://localhost:2375/');
$containerList = $client->containerList(true);
try {
$containers = React\Async\await($containerList);
// var_dump($containers);
$html_tmp = array(
'g1' => '<ul class="mylist row">', //分组开始标签
'g2' => '<li id="group_{group_id}" class="title"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-remen"></use></svg><sapn>{group_name}</sapn></li>', //分组内容
'g3' => '</ul>', //分组结束标签
'l1' => '<li class="col-3 col-sm-3 col-md-3 col-lg-1">', //链接开始标签
'l2' => '<a rel="nofollow" href="{link_url}" target="_blank"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-home00"></use></svg><span>{link_name}</span></a>', //链接内容
'l3' => '</li>', //链接结束标签
);
$html_data = rearr(['group_id' => 0, 'group_name' => 'MyDocker'], $html_tmp);
echo $html_data['g1'] . $html_data['g2'];
foreach ($containers as $key => $container) {
$data['port'] = $container['Ports'][0]['PublicPort'];
$data['state'] = $container['State'];
$data['status'] = $container['Status'];
$data['link_name'] = ltrim($container['Names'][0], '/');;
$data['link_url'] = 'http://lylme.lhp:' . $data['port'] . '/';
echo '<li class="col-3 col-sm-3 col-md-3 col-lg-1">'; //链接开始标签
if ($data['state'] == 'running') {
$state = '';
} else {
$state = 'style="filter: grayscale(100%);"';
$data['link_url'] = '#';
}
echo '<a rel="nofollow" href="' . $data['link_url'] . '" target="_blank"><svg ' . $state . ' class="icon" aria-hidden="true"><use xlink:href="#icon-home00"></use></svg><span>' . $data['link_name'] . '</span></a>'; //链接内容
echo "</li>"; //链接结束标签
}
echo $html_data['g3'];
} catch (Exception $e) {
}
}
}
到了这里,关于在六零导航页中使用插件的方式同步阻塞的方式加载docker中的应用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!