# Docker Heap Dump

**URL:** <https://discuss.elastic.co/t/docker-heap-dump/309240>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [July 9, 2022, 2:16am UTC](https://discuss.elastic.co/t/docker-heap-dump/309240 "2022-07-09T02:16:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stef\_Nestor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stef_nestor/32/85483_2.png) [@Stef\_Nestor](https://discuss.elastic.co/u/Stef_Nestor)\
**Post date:** [July 9, 2022, 2:16am UTC](https://discuss.elastic.co/t/docker-heap-dump/309240/1 "2022-07-09T02:16:33Z")

</div>

👋, howdy!

How do you grab an ES Docker heap dump? From basic setup:

```auto
$ docker run -it -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.17.0
$ docker exec -it CONTAINER_ID bash

```

Trying close to the [ECK heap dump guide](https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-jvm-heap-dumps.html#k8s_taking_add_hoc_heap_dumps)

```auto
root@CONTAINER_ID:/# /usr/share/elasticsearch/jdk/bin/jmap -dump:format=b,file=heap.hprof $(pgrep java)

Exception in thread "main" com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file /proc/8/root/tmp/.java_pid8: target process 8 doesn't respond within 10500ms or HotSpot VM not loaded
	at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:104)
	at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
	at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
	at jdk.jcmd/sun.tools.jmap.JMap.executeCommandForPid(JMap.java:128)
	at jdk.jcmd/sun.tools.jmap.JMap.dump(JMap.java:248)
	at jdk.jcmd/sun.tools.jmap.JMap.main(JMap.java:114)

```

This google returns that I'm [running as the wrong user](https://icode.best/i/38180039940793). So checking

```auto
root@CONTAINER_ID:/# whoami
root

root@CONTAINER_ID:/# ps -ef | grep java | awk '{print($1,"\t",$2, "\t", $8)}'
elastic+ 7 /usr/share/elasticsearch/jdk/bin/java
root 289 grep

```

However, attempting variations of switcher user `su`, I'm unable to get the right user to take a heap dump.

```auto
root@CONTAINER_ID:/# su - elastic+
su: user elastic+ does not exist
root@CONTAINER_ID:/# su "elastic+"
su: user elastic+ does not exist
root@CONTAINER_ID:/# su - elastic
su: user elastic does not exist

```

AFAICT from [this Stackoverflow](https://stackoverflow.com/questions/25438983/com-sun-tools-attach-attachnotsupportedexception-unable-to-open-socket-file-ta), there's no alternative to shifting to the correct user to gain access to capturing the heap dump successfully. (Similar [Discuss ballpark](https://discuss.elastic.co/search?q=docker%20%22heap%20dump%22%20tags%3Adocker), but not resolving: [Discuss#171363](https://discuss.elastic.co/t/how-to-take-jmap-dump-inside-elasticsearch-docker-container/171363). No error related [ES issues](https://github.com/elastic/elasticsearch/issues?q=is%3Aissue+is%3Aopen+AttachNotSupportedException).)

I am expecting a workflow similar to [this Medium](https://iceburn.medium.com/thread-and-heap-dumps-in-docker-containers-9aada82226fb), but have gotten myself caught on this `elastic+` user. Can someone tell me how to run this heap dump successfully? TIA! 🙏

---

<div class="post-metadata">

**Author:** ![Stef\_Nestor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stef_nestor/32/85483_2.png) [@Stef\_Nestor](https://discuss.elastic.co/u/Stef_Nestor)\
**Post date:** [July 30, 2022, 2:12am UTC](https://discuss.elastic.co/t/docker-heap-dump/309240/2 "2022-07-30T02:12:56Z")

</div>

I had a hint forward that `elastic+` is a shortened username.

```auto
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
74b698da5ea3 docker.elastic.co/elasticsearch/elasticsearch:7.17.4 "/bin/tini -- /usr/l…" 17 minutes ago Up 17 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp confident_ritchie
$ docker exec -it 74b698da5ea3 bash
> root@74b698da5ea3:/usr/share/elasticsearch# cat /etc/passwd | grep -E 'root|elastic'
root:x:0:0:root:/root:/bin/bash
elasticsearch:x:1000:1000:,,,:/usr/share/elasticsearch:/bin/bash
> root@74b698da5ea3:/usr/share/elasticsearch# su elasticsearch
> elasticsearch@74b698da5ea3:~$ pgrep java
8
> elasticsearch@74b698da5ea3:~$ ./jdk/bin/jmap -dump:live,format=b,file=heap.hprof 8
Exception in thread "main" com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file /proc/8/root/tmp/.java_pid8: target process 8 doesn't respond within 10500ms or HotSpot VM not loaded
    at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:105)
    at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
    at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
    at jdk.jcmd/sun.tools.jmap.JMap.executeCommandForPid(JMap.java:127)
    at jdk.jcmd/sun.tools.jmap.JMap.dump(JMap.java:243)
    at jdk.jcmd/sun.tools.jmap.JMap.main(JMap.java:114)

```

Still erred but now we know more about the permission group we actually need on `docker exec`:

```auto
$ docker exec -u 1000:0 -it 74b698da5ea3 bash
elasticsearch@74b698da5ea3:~$ ./jdk/bin/jmap -dump:format=b,file=heap.hprof 8
Dumping heap to /usr/share/elasticsearch/heap.hprof ...
Heap dump file created [1033192790 bytes in 2.171 secs]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 27, 2022, 2:13am UTC](https://discuss.elastic.co/t/docker-heap-dump/309240/3 "2022-08-27T02:13:46Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
