code: def _build_image_from_context(context_dir: str, image_name: str):
      import docker
  
      client = docker.from_env()
      # In Docker < 19, `docker build` doesn't support the `--platform` option
      is_platform_supported = (
          int(client.version()["Version"].split(".")[0]) >= 19
      )
      # Enforcing the AMD64 architecture build for Apple M1 users
      platform_option = (
          ["--platform", "linux/amd64"] if is_platform_supported else []
      )
      commands = [
          "docker",
          "build",
          "-t",
          image_name,
          "-f",
          "Dockerfile",
          *platform_option,
          ".",
      ]
      proc = Popen(
          commands,
          cwd=context_dir,
          stdout=PIPE,
          stderr=STDOUT,
          text=True,
      )
      for x in iter(proc.stdout.readline, ""):
          eprint(x, end="")
  
      if proc.wait():
          raise RuntimeError("Docker build failed.")
  
file_path: mlflow/mlflow/models/docker_utils.py
imports: import logging
  import os
  from subprocess import PIPE, STDOUT, Popen
  from urllib.parse import urlparse
  from mlflow.utils import env_manager
  from mlflow.utils.file_utils import TempDir, _copy_project
  from mlflow.utils.logging_utils import eprint
  from mlflow.version import VERSION
label_desc: Use image node_id 5 for calling a global function with example usage: _build_image_from_context(context_dir, image_name) without return types