You need to raise the client heap size. For a one-off change, you can do the below:
~> export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS -Xmx5g"
~> hadoop fs -copyToLocal /user/docsearch/data/DiscardedAttachments /opt/
For a more permanent change, locate Gateway Client Java Heap configs in the relevant service (HDFS, YARN or Hive) in CM, raise the value and redeploy cluster-wide configs [1].
[1] -
https://www.youtube.com/watch?v=4S9H3wftM_0