class_docstr: This EnvironmentDriver handles environment management in the project using docker
  
  Parameters
  ----------
  root : str, optional
      home filepath for project
      (default is empty)
  docker_execpath : str, optional
      execution path for docker
      (default is "docker" which defers to system)
  docker_socket : str, optional
      socket path to docker daemon to connect
      (default is None, this takes the default path for the system)
  
  Attributes
  ----------
  root : str
      home filepath for project
  datmo_directory_name : str
      datmo directory name for project
  docker_execpath : str, optional
      docker execution path for the system
  docker_socket : str, optional
      specific socket for docker
      (default is None, which means system default is used by docker)
  client : DockerClient
      docker python api client
  cpu_prefix : list
      list of strings for the prefix command for all docker commands
  info : dict
      information about the docker daemon connection
  is_connected : bool
      True if connected to daemon else False
  type : str
      type of EnvironmentDriver
class_docstr_tok: ["This","EnvironmentDriver","handles","environment","management","in","the","project","using","docker","Parameters","--","--","--","--","--","root",":","str",",","optional","home","filepath","for","project","(","default","is","empty",")","docker_execpath",":","str",",","optional","execution","path","for","docker","(","default","is","``","docker","''","which","defers","to","system",")","docker_socket",":","str",",","optional","socket","path","to","docker","daemon","to","connect","(","default","is","None",",","this","takes","the","default","path","for","the","system",")","Attributes","--","--","--","--","--","root",":","str","home","filepath","for","project","datmo_directory_name",":","str","datmo","directory","name","for","project","docker_execpath",":","str",",","optional","docker","execution","path","for","the","system","docker_socket",":","str",",","optional","specific","socket","for","docker","(","default","is","None",",","which","means","system","default","is","used","by","docker",")","client",":","DockerClient","docker","python","api","client","cpu_prefix",":","list","list","of","strings","for","the","prefix","command","for","all","docker","commands","info",":","dict","information","about","the","docker","daemon","connection","is_connected",":","bool","True","if","connected","to","daemon","else","False","type",":","str","type","of","EnvironmentDriver"]
docstr: Log capture at a particular point `docker logs`. Can also use `--follow` for real time logs
  
  Parameters
  ----------
  container_id : str
      Docker container id
  filepath : str
      Filepath to store log file
  api : bool
      True to use the docker python api
  follow : bool
      Tail the output
  
  Returns
  -------
  return_code : str
      Process return code for the container
  logs : str
      Output logs read into a string format
docstr_tok: ["Log","capture","at","a","particular","point","`","docker","logs","`",".","Can","also","use","`","--","follow","`","for","real","time","logs","Parameters","--","--","--","--","--","container_id",":","str","Docker","container","id","filepath",":","str","Filepath","to","store","log","file","api",":","bool","True","to","use","the","docker","python","api","follow",":","bool","Tail","the","output","Returns","--","--","--","-","return_code",":","str","Process","return","code","for","the","container","logs",":","str","Output","logs","read","into","a","string","format"]
code: def log_container(
      self, container_id, filepath, api=False, follow=True
  ):
      """Log capture at a particular point `docker logs`. Can also use `--follow` for real time logs
  
      Parameters
      ----------
      container_id : str
          Docker container id
      filepath : str
          Filepath to store log file
      api : bool
          True to use the docker python api
      follow : bool
          Tail the output
  
      Returns
      -------
      return_code : str
          Process return code for the container
      logs : str
          Output logs read into a string format
      """
      # TODO: Fix function to better accomodate all logs in the same way
      if api:  # calling the docker client via the API
          with open(filepath, "wb") as log_file:
              for line in self.client.containers.get(container_id).logs(
                  stream=True
              ):
                  log_file.write(to_bytes(line.strip() + os.linesep))
      else:
          command = list(self.prefix)
          if follow:
              command.extend(["logs", "--follow", str(container_id)])
          else:
              command.extend(["logs", str(container_id)])
          process = subprocess.Popen(
              command, stdout=subprocess.PIPE, universal_newlines=True
          )
          with open(filepath, "wb") as log_file:
              while True:
                  output = process.stdout.readline()
                  if output == "" and process.poll() is not None:
                      break
                  if output:
                      printable_output = output.strip().replace(
                          "\x08", " "
                      )
                      log_file.write(
                          to_bytes(printable_output + os.linesep)
                      )
          return_code = process.poll()
          with open(filepath, "rb") as log_file:
              logs = log_file.read()
              if type(logs) != str:  # handle for python 3x
                  logs = logs.decode("utf-8")
          return return_code, logs
  
imports: import ast
  import os
  import shutil
  import re
  import time
  import json
  import subprocess
  import platform
  from io import open
  from docker import DockerClient
  from docker import errors
  from datmo.core.util.i18n import get
  from datmo.core.util.exceptions import PathDoesNotExist, EnvironmentInitFailed, EnvironmentConnectFailed, EnvironmentExecutionError, FileAlreadyExistsError, EnvironmentRequirementsCreateError, EnvironmentImageNotFound, EnvironmentContainerNotFound, GPUSupportNotEnabled, EnvironmentDoesNotExist, FileStructureError
  from datmo.core.controller.environment.driver import EnvironmentDriver
label_desc: Use image node_id 34 for calling the DockerEnvironmentDriver obj's underlying member method code with example usage: obj.log_container(container_id, filepath, api, follow) and returns: return_code,  logs