@@ -22,37 +22,40 @@ public function __construct($socket = '/var/run/docker.sock', $host = 'localhost
22
22
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
23
23
curl_setopt ($ ch , CURLOPT_URL , "http:// $ this ->HOST /info " );
24
24
$ host_info = json_decode (curl_exec ($ ch ), true );
25
- if ($ host_info ['Swarm ' ]['LocalNodeState ' ] == 'active ' ){
26
- $ this ->swarm = 'services ' ;
27
- }else {
28
- $ this ->swarm = 'containers/json?{\"status\":[\"running\"]} ' ;
29
- }
25
+ curl_close ($ ch );
26
+ $ this ->swarm = $ host_info ['Swarm ' ]['LocalNodeState ' ];
30
27
}
28
+
31
29
public function get_containers (){
30
+
31
+ if ($ this ->swarm === 'active ' ){
32
+ $ containers = $ this ->docker_swarm ();
33
+ }
34
+ $ containers = $ this ->docker_node ($ containers );
35
+
36
+ return $ containers ;
37
+ }
38
+
39
+ private function docker_node ($ node_containers ){
32
40
set_time_limit (0 );
33
41
$ ch = $ this ->connection ;
34
42
curl_setopt ($ ch , CURLOPT_UNIX_SOCKET_PATH , $ this ->SOCKET );
35
43
curl_setopt ($ ch , CURLOPT_BUFFERSIZE , 256 );
36
44
curl_setopt ($ ch , CURLOPT_TIMEOUT , 1000000 );
37
45
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
38
- curl_setopt ($ ch , CURLOPT_URL , "http:// $ this ->HOST / $ this -> swarm " );
46
+ curl_setopt ($ ch , CURLOPT_URL , "http:// $ this ->HOST /containers/json?{ \" status \" :[ \" running \" ]} " );
39
47
$ containers = json_decode (curl_exec ($ ch ), true );
40
48
curl_close ($ ch );
41
- if ($ this ->swarm === 'services ' ){
42
- return $ this ->docker_swarm ($ containers );
43
- }else {
44
- return $ this ->docker_node ($ containers );
45
- }
46
- }
47
49
48
- private function docker_node ($ containers ){
49
50
$ count = count ($ containers );
50
- $ container_list = array ();
51
- $ d = 0 ;
51
+ $ container_list = json_decode ($ node_containers , true );
52
+ $ start = count ($ container_list );
53
+ $ d = $ start ;
52
54
for ($ c = 0 ; $ c < $ count ; $ c ++){
53
55
if ( (array_key_exists ('dashboard.ignore ' , $ containers [$ c ]['Labels ' ]) === false ) ||
54
56
( array_key_exists ('traefik.enable ' , $ containers [$ c ]['Labels ' ]) &&
55
- $ containers [$ c ]['Labels ' ]['traefik.enable ' ] === false )
57
+ $ containers [$ c ]['Labels ' ]['traefik.enable ' ] === false ) ||
58
+ (array_key_exists ('com.docker.stack.namespace ' , $ containers [$ c ]['Labels ' ]) === false )
56
59
){
57
60
$ container_list [$ d ]['name ' ] = str_replace ('/ ' , '' , $ containers [$ c ]['Names ' ][0 ]);
58
61
foreach ($ containers [$ c ]['Labels ' ] as $ key => $ label ){
@@ -90,7 +93,17 @@ private function docker_node($containers){
90
93
return json_encode ($ container_list );
91
94
}
92
95
93
- private function docker_swarm ($ containers ){
96
+ private function docker_swarm (){
97
+ set_time_limit (0 );
98
+ $ ch = $ this ->connection ;
99
+ curl_setopt ($ ch , CURLOPT_UNIX_SOCKET_PATH , $ this ->SOCKET );
100
+ curl_setopt ($ ch , CURLOPT_BUFFERSIZE , 256 );
101
+ curl_setopt ($ ch , CURLOPT_TIMEOUT , 1000000 );
102
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
103
+ curl_setopt ($ ch , CURLOPT_URL , "http:// $ this ->HOST /services " );
104
+ $ containers = json_decode (curl_exec ($ ch ), true );
105
+ curl_close ($ ch );
106
+
94
107
$ count = count ($ containers );
95
108
$ container_list = array ();
96
109
$ d = 0 ;
0 commit comments