def METHOD_NAME(container_name,
                  cmd_array,
                  workdir=None,
                  logfile=None,
                  detach=False):
  """Execute in docker container."""
  if not workdir:
    workdir = "/tmp"
  opts = ["-t", "-w", workdir]
  if detach:
    opts += ["-d"]
  # TODO(drpng): avoid quoting hell.
  base_cmd = ["exec"] + opts + [container_name]
  if logfile:
    # The logfile is in the container.
    cmd = " ".join(shell_quote(x) for x in cmd_array)
    cmd += " >& %s" % logfile
    full_cmd = base_cmd + ["bash", "-c", cmd]
  else:
    full_cmd = base_cmd + cmd_array
  ret = _RunDocker(full_cmd)
  if ret != 0:
    sys.stderr.write(
        "Failed to exec within %s: %s" % (container_name, cmd_array))
    sys.exit(ret)