class_docstr: Handle the lifecycle and configuration of a local container execution.
  
  This class is responsible for creating the directories and configuration
  files that the docker containers will use for either training or serving.
class_docstr_tok: ["Handle","the","lifecycle","and","configuration","of","a","local","container","execution",".","This","class","is","responsible","for","creating","the","directories","and","configuration","files","that","the","docker","containers","will","use","for","either","training","or","serving","."]
docstr: Initialize a SageMakerContainer instance
  
  It uses a :class:`sagemaker.session.Session` for general interaction
  with user configuration such as getting the default sagemaker S3 bucket.
  However this class does not call any of the SageMaker APIs.
  
  Args:
      instance_type (str): The instance type to use. Either 'local' or
          'local_gpu'
      instance_count (int): The number of instances to create.
      image (str): docker image to use.
      sagemaker_session (sagemaker.session.Session): a sagemaker session
          to use when interacting with SageMaker.
      container_entrypoint (str): the container entrypoint to execute
      container_arguments (str): the container entrypoint arguments
docstr_tok: ["Initialize","a","SageMakerContainer","instance","It","uses","a",":","class",":","`","sagemaker.session.Session","`","for","general","interaction","with","user","configuration","such","as","getting","the","default","sagemaker","S3","bucket",".","However","this","class","does","not","call","any","of","the","SageMaker","APIs",".","Args",":","instance_type","(","str",")",":","The","instance","type","to","use",".","Either","'local","'","or","'local_gpu'","instance_count","(","int",")",":","The","number","of","instances","to","create",".","image","(","str",")",":","docker","image","to","use",".","sagemaker_session","(","sagemaker.session.Session",")",":","a","sagemaker","session","to","use","when","interacting","with","SageMaker",".","container_entrypoint","(","str",")",":","the","container","entrypoint","to","execute","container_arguments","(","str",")",":","the","container","entrypoint","arguments"]
code: def __init__(
      self,
      instance_type,
      instance_count,
      image,
      sagemaker_session=None,
      container_entrypoint=None,
      container_arguments=None,
  ):
      """Initialize a SageMakerContainer instance
  
      It uses a :class:`sagemaker.session.Session` for general interaction
      with user configuration such as getting the default sagemaker S3 bucket.
      However this class does not call any of the SageMaker APIs.
  
      Args:
          instance_type (str): The instance type to use. Either 'local' or
              'local_gpu'
          instance_count (int): The number of instances to create.
          image (str): docker image to use.
          sagemaker_session (sagemaker.session.Session): a sagemaker session
              to use when interacting with SageMaker.
          container_entrypoint (str): the container entrypoint to execute
          container_arguments (str): the container entrypoint arguments
      """
      from sagemaker.local.local_session import LocalSession
  
      # check if docker-compose is installed
  
      self.compose_cmd_prefix = (
          _SageMakerContainer._get_compose_cmd_prefix()
      )
      self.sagemaker_session = sagemaker_session or LocalSession()
      self.instance_type = instance_type
      self.instance_count = instance_count
      self.image = image
      self.container_entrypoint = container_entrypoint
      self.container_arguments = container_arguments
      # Since we are using a single docker network, Generate a random suffix to attach to the
      # container names. This way multiple jobs can run in parallel.
      suffix = "".join(
          random.choice(string.ascii_lowercase + string.digits)
          for _ in range(5)
      )
      self.is_studio = sagemaker.local.utils.check_for_studio()
      if self.is_studio:
          if self.instance_count > 1:
              raise NotImplementedError(
                  "Multi instance Local Mode execution is "
                  "currently not supported in SageMaker Studio."
              )
          # For studio use-case, directories need to be created in `~/tmp`, rather than /tmp
          home = os.path.expanduser("~")
          root_dir = os.path.join(home, "tmp")
          if not os.path.isdir(root_dir):
              os.mkdir(root_dir)
          if self.sagemaker_session.config:
              self.sagemaker_session.config["local"][
                  "container_root"
              ] = root_dir
          else:
              self.sagemaker_session.config = {
                  "local": {"container_root": root_dir}
              }
          # Studio only supports single instance run
          self.hosts = [STUDIO_HOST_NAME]
      else:
          self.hosts = [
              "{}-{}-{}".format(CONTAINER_PREFIX, i, suffix)
              for i in range(1, self.instance_count + 1)
          ]
  
      self.container_root = None
      self.container = None
  
imports: from __future__ import absolute_import, annotations
  import base64
  import copy
  import errno
  import json
  import logging
  import os
  import platform
  import random
  import re
  import shlex
  import shutil
  import string
  import subprocess
  import sys
  import tarfile
  import tempfile
  from distutils.spawn import find_executable
  from threading import Thread
  from typing import Dict, List
  from six.moves.urllib.parse import urlparse
  import sagemaker
  from sagemaker.config.config_schema import CONTAINER_CONFIG, LOCAL
  import sagemaker.local.data
  import sagemaker.local.utils
  import sagemaker.utils
label_desc: Use image node_id 1 to create a new _SageMakerContainer object from inherited base classes: object with example: obj = _SageMakerContainer(instance_type, instance_count, image, sagemaker_session, container_entrypoint, container_arguments)