code: def _build_container(sagemaker_session, py_version, docker_templete):
      """Build a dummy test container locally and push a container to an ecr repo"""
  
      region = sagemaker_session.boto_region_name
      image_tag = (
          f"{py_version.replace('.', '-')}-{sagemaker_timestamp()}"
      )
      ecr_client = sagemaker_session.boto_session.client("ecr")
      username, password = _ecr_login(ecr_client)
  
      with _tmpdir() as tmpdir:
          print("building docker image locally in ", tmpdir)
          print("building source archive...")
          source_archive = _generate_sagemaker_sdk_tar(tmpdir)
          with open(os.path.join(tmpdir, "Dockerfile"), "w") as file:
              file.writelines(
                  docker_templete.format(
                      py_version=py_version,
                      source_archive=source_archive,
                  )
              )
  
          docker_client = docker.from_env()
  
          print("building docker image...")
          # platform is provided to make sure that the image builds correctly across different OS platforms
          try:
              image, build_logs = docker_client.images.build(
                  path=tmpdir,
                  tag=REPO_NAME,
                  rm=True,
                  platform="linux/amd64",
              )
          except BuildError as e:
              print("docker build failed!")
              for line in e.build_log:
                  if "stream" in line:
                      print(line["stream"].strip())
              raise
  
      if _is_repository_exists(ecr_client, REPO_NAME):
          sts_client = sagemaker_session.boto_session.client(
              "sts",
              region_name=region,
              endpoint_url=sts_regional_endpoint(region),
          )
          account_id = sts_client.get_caller_identity()["Account"]
          # When the test is run locally, repo will exist in same account whose credentials are used to run the test
          ecr_image = _ecr_image_uri(
              account_id,
              sagemaker_session.boto_region_name,
              REPO_NAME,
              image_tag,
          )
      else:
          ecr_image = _ecr_image_uri(
              REPO_ACCOUNT_ID,
              sagemaker_session.boto_region_name,
              REPO_NAME,
              image_tag,
          )
  
      print("pushing image...")
      image.tag(ecr_image, tag=image_tag)
      docker_client.images.push(
          ecr_image,
          auth_config={"username": username, "password": password},
      )
  
      return ecr_image
  
imports: from __future__ import absolute_import
  import base64
  import os
  import subprocess
  import shutil
  import pytest
  import docker
  import re
  import sys
  from docker.errors import BuildError
  from sagemaker.utils import sagemaker_timestamp, _tmpdir, sts_regional_endpoint
label_desc: Use image node_id 10 for calling a global function with example usage: _build_container(sagemaker_session, py_version, docker_templete) and returns: ecr_image