I'd like to use an environment variable to set -XX:HeapDumpPath
option on JVM startup. Moreover, I'd like this to work inside a Docker container and in such a way that my JVM process gets PID 1. This seems to make all the proposed solutions in this question invalid for my case.
My current solution looks like this:
Dockerfile
FROM openjdk:10 COPY . . ENTRYPOINT [ "./start.sh" ]
start.sh
#!/usr/bin/env bash exec java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${HEAP_DUMP_PATH} -jar build/libs/app.jar
If I build it with docker build --tag=test .
and then run with CID=$(docker run --rm -e HEAP_DUMP_PATH="/tmp" -d test) && docker exec $CID ps -f
I get:
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 16:18 ? 00:00:00 java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -jar build/libs/app.jar
root 21 0 0 16:18 ? 00:00:00 ps -f
So it seems to be working. But it also seems unnecessarily complicated. Is there a better/cleaner way to achieve this?
Update: removed -c
in exec -c
.