mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-16 10:16:12 +01:00
bug fix: call function to install docker
This commit is contained in:
@@ -705,38 +705,39 @@ services:
|
|||||||
## This function need site name which was passed while creating the app
|
## This function need site name which was passed while creating the app
|
||||||
def ListContainers(self):
|
def ListContainers(self):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# Create a Docker client
|
# Create a Docker client
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
|
|
||||||
FilerValue = self.DockerAppName
|
FilerValue = self.DockerAppName
|
||||||
|
|
||||||
# Define the label to filter containers
|
# List all containers and filter by name
|
||||||
label_filter = {'name': FilerValue}
|
all_containers = client.containers.list(all=True) # all=True to show both running and stopped containers
|
||||||
|
containers = [c for c in all_containers if FilerValue in c.name]
|
||||||
|
|
||||||
# List containers matching the label filter
|
|
||||||
containers = client.containers.list(filters=label_filter)
|
|
||||||
|
|
||||||
json_data = "["
|
json_data = "["
|
||||||
checker = 0
|
checker = 0
|
||||||
|
|
||||||
for container in containers:
|
for container in containers:
|
||||||
|
try:
|
||||||
|
dic = {
|
||||||
|
'id': container.short_id,
|
||||||
|
'name': container.name,
|
||||||
|
'status': container.status,
|
||||||
|
'state': container.attrs.get('State', {}),
|
||||||
|
'health': container.attrs.get('State', {}).get('Health', {}).get('Status', 'unknown'),
|
||||||
|
'volumes': container.attrs['HostConfig']['Binds'] if 'HostConfig' in container.attrs else [],
|
||||||
|
'logs_50': container.logs(tail=50).decode('utf-8'),
|
||||||
|
'ports': container.attrs['HostConfig']['PortBindings'] if 'HostConfig' in container.attrs else {}
|
||||||
|
}
|
||||||
|
|
||||||
dic = {
|
if checker == 0:
|
||||||
'id': container.short_id,
|
json_data = json_data + json.dumps(dic)
|
||||||
'name': container.name,
|
checker = 1
|
||||||
'status': container.status,
|
else:
|
||||||
'volumes': container.attrs['HostConfig']['Binds'] if 'HostConfig' in container.attrs else [],
|
json_data = json_data + ',' + json.dumps(dic)
|
||||||
'logs_50': container.logs(tail=50).decode('utf-8'),
|
except Exception as e:
|
||||||
'ports': container.attrs['HostConfig']['PortBindings'] if 'HostConfig' in container.attrs else {}
|
logging.writeToFile(f"Error processing container {container.name}: {str(e)}")
|
||||||
}
|
continue
|
||||||
|
|
||||||
if checker == 0:
|
|
||||||
json_data = json_data + json.dumps(dic)
|
|
||||||
checker = 1
|
|
||||||
else:
|
|
||||||
json_data = json_data + ',' + json.dumps(dic)
|
|
||||||
|
|
||||||
json_data = json_data + ']'
|
json_data = json_data + ']'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user