code: def _build_docker_images(use_test_docker_file=True):
      image_name = "mars-test-image:" + uuid.uuid1().hex
      try:
          if use_test_docker_file:
              proc = subprocess.Popen(
                  [
                      "docker",
                      "build",
                      "-f",
                      "Dockerfile.test",
                      "-t",
                      image_name,
                      ".",
                  ],
                  cwd=TEST_ROOT,
              )
          else:
              proc = subprocess.Popen(
                  [
                      "docker",
                      "build",
                      "-f",
                      os.path.join(DOCKER_ROOT, "Dockerfile"),
                      "-t",
                      image_name,
                      ".",
                  ],
                  cwd=MARS_ROOT,
              )
          if proc.wait() != 0:
              raise SystemError("Executing docker build failed.")
  
          if use_test_docker_file:
              proc = subprocess.Popen(
                  [
                      "docker",
                      "run",
                      "-v",
                      MARS_ROOT + ":/mnt/mars",
                      image_name,
                      "/srv/build_ext.sh",
                  ]
              )
              if proc.wait() != 0:
                  raise SystemError("Executing docker run failed.")
      except:  # noqa: E722
          _remove_docker_image(image_name)
          raise
      return image_name
  
imports: import glob
  import os
  import shutil
  import subprocess
  import tempfile
  import uuid
  from contextlib import contextmanager
  from distutils.spawn import find_executable
  import numpy
  import pytest
  from ....None import tensor
  from ....tests.core import mock
  from ..None import new_cluster
  from ..config import HostPathVolumeConfig
label_desc: Use image node_id 2 for calling a global function with example usage: _build_docker_images(use_test_docker_file) and returns: image_name