docker clean

This commit is contained in:
mercury
2024-04-22 21:49:55 +04:00
parent 581e3a9bd1
commit f4a9e63793
4 changed files with 47 additions and 1 deletions
+43
View File
@@ -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();
+1
View File
@@ -40,3 +40,4 @@ file_put_contents('/update/message', '');
file_put_contents('/update/reload_message', '');
$bot->restartTG();
$bot->sslip();
$bot->cleanDocker();
+2
View File
@@ -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}
+1 -1
View File
@@ -9,7 +9,7 @@ d: # остановка контейнеров
docker compose down --remove-orphans
dv: # остановка контейнеров
docker compose down -v
r: d cleanf u cleanf
r: d u
ps: # список контейнеров
docker compose ps
l: # логи из контейнеров