import subprocess,sys,time for _ in range(90): if subprocess.check_output(['docker','inspect','-f','{{.State.Health.Status}}',sys.argv[1]],text=True).strip()=='healthy': time.sleep(2) # allow HAProxy rise check and DNS refresh break time.sleep(1) else: raise SystemExit('container did not become ready')