use docker ps for removal search
All checks were successful
Deploy Containers / Prepare (push) Successful in 5s
All checks were successful
Deploy Containers / Prepare (push) Successful in 5s
This commit is contained in:
@@ -86,19 +86,18 @@ def main():
|
|||||||
|
|
||||||
for task in removed_containers:
|
for task in removed_containers:
|
||||||
print(f"[MAIN] Attempting to remove containers related to '{task}'...")
|
print(f"[MAIN] Attempting to remove containers related to '{task}'...")
|
||||||
task_name = task.split("/")[1].split(".")[0]
|
if len(task.split("/")) > 1:
|
||||||
|
task_name = task.split("/")[1].split(".")[0]
|
||||||
containers = subprocess.Popen(f"docker container list | grep {task_name}_", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
else:
|
||||||
|
task_name = task
|
||||||
|
|
||||||
|
containers = subprocess.Popen(f'docker ps --filter "name={task_name}" -q', shell=True, stdout=subprocess.PIPE)
|
||||||
for line in containers.stdout:
|
for line in containers.stdout:
|
||||||
docker_container_id = line.rstrip().decode('utf8').split(" ")[0]
|
print(f"[MAIN] Found Docker container {line} related to {task_name}, removing..")
|
||||||
if docker_container_id and docker_container_id.strip() != "":
|
subprocess.run(f"/usr/bin/docker container stop {line}", shell=True)
|
||||||
print(f"[MAIN] Found Docker container {docker_container_id} related to {task}, removing..")
|
subprocess.run(f"/usr/bin/docker container rm {line}", shell=True)
|
||||||
|
subprocess.run("/usr/bin/docker image prune -f", shell=True)
|
||||||
# clean up containers & dangling images
|
subprocess.run("/usr/bin/docker container prune -f", shell=True)
|
||||||
subprocess.run(f"/usr/bin/docker container stop {docker_container_id}", shell=True, stdout=subprocess.DEVNULL)
|
|
||||||
subprocess.run(f"/usr/bin/docker container rm {docker_container_id}", shell=True, stdout=subprocess.DEVNULL)
|
|
||||||
subprocess.run("/usr/bin/docker image prune -f", shell=True, stdout=subprocess.DEVNULL)
|
|
||||||
subprocess.run("/usr/bin/docker container prune -f", shell=True, stdout=subprocess.DEVNULL)
|
|
||||||
|
|
||||||
if len(failed) <= 0 and len(deployed) > 0:
|
if len(failed) <= 0 and len(deployed) > 0:
|
||||||
print("\n---------------------")
|
print("\n---------------------")
|
||||||
|
|||||||
Reference in New Issue
Block a user