code: def _docker_run(
      client: "DockerClient",
      args: "argparse.Namespace",
      container_name: str,
      envs: Dict,
      net_mode: Optional[str],
      logger: "JinaLogger",
  ):
      # important to notice, that client is not assigned as instance member to avoid potential
      # heavy copy into new process memory space
      import warnings
      import docker
  
      docker_version = client.version().get("Version")
      if not docker_version:
          raise DockerVersionError("docker version can not be resolved")
  
      docker_version = tuple(docker_version.split("."))
      # docker daemon versions below 20.0x do not support "host.docker.internal:host-gateway"
      if docker_version < ("20",):
          raise DockerVersionError(
              f'docker version {".".join(docker_version)} is below 20.0.0 and does not '
              f'support "host.docker.internal:host-gateway" : https://github.com/docker/cli/issues/2664'
          )
  
      if args.uses.startswith("docker://"):
          uses_img = args.uses.replace("docker://", "")
          logger.debug(f"will use Docker image: {uses_img}")
      else:
          warnings.warn(
              f"you are using legacy image format {args.uses}, this may create some ambiguity. "
              f'please use the new format: "--uses docker://{args.uses}"'
          )
          uses_img = args.uses
  
      # the image arg should be ignored otherwise it keeps using ContainerPod in the container
      # basically all args in Pod-docker arg group should be ignored.
      # this prevent setting containerPod twice
      from pathlib import Path
  
      from jina.helper import ArgNamespace
      from jina.parsers import set_pod_parser
  
      args.native = True
  
      parser = (
          set_gateway_parser()
          if args.pod_role == PodRoleType.GATEWAY
          else set_pod_parser()
      )
  
      non_defaults = ArgNamespace.get_non_defaults_args(
          args,
          parser,
          taboo={
              "uses",
              "entrypoint",
              "volumes",
              "pull_latest",
              "docker_kwargs",
              "gpus",
          },
      )
      img_not_found = False
  
      try:
          client.images.get(uses_img)
      except docker.errors.ImageNotFound:
          logger.error(f"can not find local image: {uses_img}")
          # try to pull the image
          try:
              logger.debug(f"pulling image: {uses_img}")
              client.images.pull(uses_img)
              logger.debug(f"pulled image: {uses_img}")
              logger.debug(f"getting image: {uses_img}")
              client.images.get(uses_img)
              logger.debug(f"successfully got image: {uses_img}")
              img_not_found = False
          except docker.errors.ImageNotFound:
              logger.error(f"can not find remote image: {uses_img}")
              img_not_found = True
  
      if img_not_found:
          raise BadImageNameError(
              f"image: {uses_img} can not be found local & remote."
          )
  
      _volumes = {}
      if not getattr(args, "disable_auto_volume", None) and not getattr(
          args, "volumes", None
      ):
          (
              generated_volumes,
              workspace_in_container,
          ) = generate_default_volume_and_workspace(
              workspace_id=args.workspace_id
          )
          args.volumes = generated_volumes
          args.workspace = (
              workspace_in_container
              if not args.workspace
              else args.workspace
          )
  
      if getattr(args, "volumes", None):
          for p in args.volumes:
              paths = p.split(":")
              local_path = paths[0]
              Path(os.path.abspath(local_path)).mkdir(
                  parents=True, exist_ok=True
              )
              if len(paths) == 2:
                  container_path = paths[1]
              else:
                  container_path = "/" + os.path.basename(p)
              _volumes[os.path.abspath(local_path)] = {
                  "bind": container_path,
                  "mode": "rw",
              }
  
      device_requests = []
      if getattr(args, "gpus", None):
          device_requests = get_gpu_device_requests(args.gpus)
          del args.gpus
  
      _args = ArgNamespace.kwargs2list(non_defaults)
  
      ports = (
          {f"{_port}/tcp": _port for _port in args.port}
          if not net_mode
          else None
      )
  
      if platform.system() == "Darwin":
          image_architecture = client.images.get(uses_img).attrs.get(
              "Architecture", ""
          )
          if not image_architecture.startswith("arm"):
              logger.warning(
                  "The pulled image container does not support ARM architecture while the host machine relies on MacOS (Darwin)."
                  "The image may run with poor performance or fail if run via emulation."
              )
      docker_kwargs = args.docker_kwargs or {}
      container = client.containers.run(
          uses_img,
          _args,
          detach=True,
          auto_remove=True,
          ports=ports,
          name=container_name,
          volumes=_volumes,
          network_mode=net_mode,
          entrypoint=args.entrypoint,
          extra_hosts={__docker_host__: "host-gateway"},
          device_requests=device_requests,
          environment=envs,
          **docker_kwargs,
      )
      return container
  
imports: import argparse
  import copy
  import multiprocessing
  import os
  import platform
  import re
  import signal
  import time
  from typing import TYPE_CHECKING, Dict, Optional, Union
  from jina.constants import __docker_host__, __windows__
  from jina.enums import PodRoleType, DockerNetworkMode
  from jina.excepts import BadImageNameError, DockerVersionError
  from jina.helper import random_name, slugify
  from jina.importer import ImportExtensions
  from jina.logging.logger import JinaLogger
  from jina.orchestrate.helper import generate_default_volume_and_workspace
  from jina.orchestrate.pods import BasePod
  from jina.orchestrate.pods.container_helper import get_docker_network, get_gpu_device_requests
  from jina.parsers import set_gateway_parser
label_desc: Use image node_id 1 for calling a global function with example usage: _docker_run(client, args, container_name, envs, net_mode, logger) and returns: container