code: def wait_for_container(container_id: str, timeout: int = 300):
      container_name = (
          subprocess.check_output(
              [
                  "docker",
                  "inspect",
                  container_id,
                  "--format",
                  "{{ .Name }}",
              ]
          )
          .decode()
          .strip()
      )
      print(
          f"Waiting for container: {container_name} [{container_id}] for {timeout} more seconds."
      )
      waiting_done = False
      start_time = monotonic()
      while not waiting_done:
          container_state = (
              subprocess.check_output(
                  [
                      "docker",
                      "inspect",
                      container_id,
                      "--format",
                      "{{ .State.Status }}",
                  ]
              )
              .decode()
              .strip()
          )
          if container_state in ("running", "restarting"):
              health_status = (
                  subprocess.check_output(
                      [
                          "docker",
                          "inspect",
                          container_id,
                          "--format",
                          "{{ if .State.Health }}{{ .State.Health.Status }}{{ else }}no-check{{ end }}",
                      ]
                  )
                  .decode()
                  .strip()
              )
              current_time = monotonic()
              print(
                  f"{container_name}: container_state={container_state}, health_status={health_status}. "
                  f"Waiting for {int(timeout - (current_time - start_time))} more seconds"
              )
  
              if (
                  health_status == "healthy"
                  or health_status == "no-check"
              ):
                  waiting_done = True
          else:
              print(
                  f"{container_name}: container_state={container_state}"
              )
              waiting_done = True
          if timeout != 0 and monotonic() - start_time > timeout:
              raise Exception(
                  f"Timeout. The operation takes longer than the maximum waiting time ({timeout}s)"
              )
          sleep(1)
  
file_path: airflow/docker_tests/test_docker_compose_quick_start.py
imports: from __future__ import annotations
  import json
  import os
  import shlex
  import subprocess
  import sys
  from pprint import pprint
  from shutil import copyfile
  from time import monotonic, sleep
  import requests
  from docker_tests.command_utils import run_command
  from docker_tests.constants import SOURCE_ROOT
  from docker_tests.docker_tests_utils import docker_image
label_desc: Use image node_id 2 for calling a global function with example usage: wait_for_container(container_id, timeout) without return types