DocSpace-buildtools/start/stop.backend.docker.py

18 lines
460 B
Python
Raw Normal View History

2023-10-19 08:55:30 +00:00
#!/usr/bin/python3
import subprocess
import time
2023-10-19 08:55:30 +00:00
start = time.time()
container_ids = subprocess.check_output("docker ps -q -f label=com.docker.compose.project=docker", encoding='utf-8')
containers = container_ids.strip().split()
2023-10-19 08:55:30 +00:00
if containers:
print("Stop all backend services (containers)")
subprocess.run(['docker', 'stop'] + containers, check=True)
else:
2023-10-19 08:55:30 +00:00
print("No containers to stop")
end = time.time()
print("\nElapsed time", end - start)