docker clean
This commit is contained in:
+43
@@ -3371,6 +3371,49 @@ DNS-over-HTTPS with IP:
|
||||
return "vless://{$c['inbounds'][0]['settings']['clients'][$i]['id']}@$domain:443?security=reality&sni={$c['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0]}&fp=chrome&pbk={$pac['xray']}&sid={$c['inbounds'][0]['streamSettings']['realitySettings']['shortIds'][0]}&type=tcp&flow=xtls-rprx-vision#vpnbot";
|
||||
}
|
||||
|
||||
public function dockerApi($url, $method = 'GET', $data = [])
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_CUSTOMREQUEST => $method,
|
||||
CURLOPT_POSTFIELDS => !empty($data) ? json_encode($data) : null,
|
||||
CURLOPT_URL => "http://localhost$url",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock'
|
||||
]);
|
||||
$r = json_decode(curl_exec($ch), true);
|
||||
curl_close($ch);
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function cleanDocker()
|
||||
{
|
||||
$r = $this->dockerApi('/images/json');
|
||||
foreach ($r as $v) {
|
||||
if (!empty($v['RepoTags'])) {
|
||||
foreach ($v['RepoTags'] as $j) {
|
||||
if (preg_match('~^mercurykd/vpnbot~', $j)) {
|
||||
$i[] = $v['Id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$r = $this->dockerApi('/containers/json?all=1');
|
||||
foreach ($r as $v) {
|
||||
if (preg_match('~^mercurykd/vpnbot~', $v['Image'])) {
|
||||
$c[] = $v['ImageID'];
|
||||
}
|
||||
}
|
||||
if (!empty($d = array_diff($i, $c))) {
|
||||
foreach ($d as $v) {
|
||||
$this->dockerApi("/images/$v", 'DELETE');
|
||||
}
|
||||
}
|
||||
$this->dockerApi('/images/prune', 'POST', ['dangling' => true]);
|
||||
$this->dockerApi('/build/prune', 'POST');
|
||||
}
|
||||
|
||||
public function naiveMenu()
|
||||
{
|
||||
$pac = $this->getPacConf();
|
||||
|
||||
@@ -40,3 +40,4 @@ file_put_contents('/update/message', '');
|
||||
file_put_contents('/update/reload_message', '');
|
||||
$bot->restartTG();
|
||||
$bot->sslip();
|
||||
$bot->cleanDocker();
|
||||
|
||||
@@ -116,6 +116,7 @@ services:
|
||||
- ./update:/update
|
||||
- ./.git:/.git
|
||||
- ./singbox_windows:/singbox
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
environment:
|
||||
IP: ${IP}
|
||||
VER: ${VER}
|
||||
@@ -157,6 +158,7 @@ services:
|
||||
- ./logs/:/logs/
|
||||
- ./update:/update
|
||||
- ./scripts/start_service.sh:/start_service.sh
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
environment:
|
||||
IP: ${IP}
|
||||
VER: ${VER}
|
||||
|
||||
Reference in New Issue
Block a user