code: def run_container_using_docker(
      worker_image: SyftWorkerImage,
      docker_client: docker.DockerClient,
      worker_name: str,
      worker_count: int,
      pool_name: str,
      queue_port: int,
      debug: bool = False,
      username: Optional[str] = None,
      password: Optional[str] = None,
      registry_url: Optional[str] = None,
  ) -> ContainerSpawnStatus:
      if not worker_image.is_built:
          raise Exception("Image must be built before running it.")
  
      # Get hostname
      hostname = socket.gethostname()
  
      # Create a random UID for Worker
      syft_worker_uid = UID()
  
      # container name
      container_name = f"{hostname}-{worker_name}"
  
      # start container
      container = None
      error_message = None
      worker = None
      try:
          # login to the registry through the client
          # so that the subsequent pull/run commands work
          if registry_url and username and password:
              docker_client.login(
                  username=username,
                  password=password,
                  registry=registry_url,
              )
  
          # If container with given name already exists then stop it
          # and recreate it.
          existing_container = get_container(
              docker_client=docker_client,
              container_name=container_name,
          )
          if existing_container:
              existing_container.remove(force=True)
  
          # Extract Config from backend container
          backend_host_config = extract_config_from_backend(
              worker_name=worker_name, docker_client=docker_client
          )
  
          # Create List of Envs to pass
          environment = backend_host_config["environment"]
          environment["CREATE_PRODUCER"] = "false"
          environment["N_CONSUMERS"] = 1
          environment["PORT"] = str(get_free_tcp_port())
          environment["HTTP_PORT"] = str(88 + worker_count)
          environment["HTTPS_PORT"] = str(446 + worker_count)
          environment["CONSUMER_SERVICE_NAME"] = pool_name
          environment["SYFT_WORKER_UID"] = syft_worker_uid
          environment["DEV_MODE"] = debug
          environment["QUEUE_PORT"] = queue_port
          environment["CONTAINER_HOST"] = "docker"
  
          container = docker_client.containers.run(
              worker_image.image_identifier.full_name_with_tag,
              name=f"{hostname}-{worker_name}",
              detach=True,
              auto_remove=True,
              network_mode=backend_host_config["network_mode"],
              environment=environment,
              volumes=backend_host_config["volume_binds"],
              tty=True,
              stdin_open=True,
              labels={
                  "orgs.openmined.syft": "this is a syft worker container"
              },
          )
  
          status = (
              WorkerStatus.STOPPED
              if container.status == "exited"
              else WorkerStatus.PENDING
          )
  
          healthcheck: WorkerHealth = _get_healthcheck_based_on_status(
              status
          )
  
          worker = SyftWorker(
              id=syft_worker_uid,
              name=worker_name,
              container_id=container.id,
              status=status,
              healthcheck=healthcheck,
              image=worker_image,
              worker_pool_name=pool_name,
          )
      except Exception as e:
          error_message = f"Failed to run command in container. {worker_name} {worker_image}. {e}. {sys.stderr}"
          if container:
              worker = SyftWorker(
                  name=worker_name,
                  container_id=container.id,
                  status=WorkerStatus.STOPPED,
                  healthcheck=WorkerHealth.UNHEALTHY,
                  image=worker_image,
                  worker_pool_name=pool_name,
              )
              container.stop()
  
      return ContainerSpawnStatus(
          worker_name=worker_name, worker=worker, error=error_message
      )
  
imports: import contextlib
  import json
  import os
  import socket
  import socketserver
  import sys
  from typing import Iterable
  from typing import List
  from typing import Optional
  from typing import Union
  import docker
  from pydantic import BaseModel
  from ...abstract_node import AbstractNode
  from ...custom_worker.builder import CustomWorkerBuilder
  from ...custom_worker.config import DockerWorkerConfig
  from ...node.credentials import SyftVerifyKey
  from ...types.uid import UID
  from ...util.util import get_queue_address
  from ..response import SyftError
  from .worker_image import SyftWorkerImage
  from .worker_image_stash import SyftWorkerImageStash
  from .worker_pool import ContainerSpawnStatus
  from .worker_pool import SyftWorker
  from .worker_pool import WorkerHealth
  from .worker_pool import WorkerOrchestrationType
  from .worker_pool import WorkerStatus
label_desc: Use image node_id 5 for calling a global function with example usage: run_container_using_docker(worker_image, docker_client, worker_name, worker_count, pool_name, queue_port, debug, username, password, registry_url) and returns: ContainerSpawnStatus