0

The problem for first time is works fine but, for next it fails to write the file with same name, So I tried adding pod_id to make it unique but seems pod id to remains same when it restarts after failing, so tried adding timestamp to the filename, but date function is being treated as string, so again the file name remains same for every restarts and heap dump file doesn't get generated next time.

ENTRYPOINT ["java","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=mountpath-heapdump/$MY_POD_ID$(date +'%Y-%m-%d_%H-%M-%S')_heapdump.bin","-jar", "/app.jar"])

I also without double quotes:

ENTRYPOINT java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=mountpath-heapdump/$MY_POD_ID$(date +'%Y-%m-%d_%H-%M-%S')_heapdump.bin -jar app.jar

working fine in POC but for my project application, environment variables are not reflecting, spring-profile was not picked. Even other environments variable too was not picked. So I am trying the first approach only I need help to append timestamp in the filename.

halfer
  • 19,824
  • 17
  • 99
  • 186
lucky
  • 331
  • 6
  • 14
  • [According to this document](https://docs.docker.com/engine/reference/builder/#entrypoint), shell processing does not occur in exec form. Therefore, it is necessary to clearly specify how to execute it. – JongWon Lee Nov 03 '21 at 13:15
  • What is the alternative then to append timestamp in the filename in Exec form? – lucky Nov 03 '21 at 13:45
  • 2
    You may try to run java inside shell `ENTRYPOINT ["bash", "-c", "java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=mountpath-heapdump/$MY_POD_ID$(date +'%Y-%m-%d_%H-%M-%S')_heapdump.bin -jar /app.jar"]` – rzlvmp Nov 03 '21 at 14:50
  • 1
    @AKASHKESHARI In addition to the very good answer provided by rzlvmp, I wrote another alternative. – JongWon Lee Nov 03 '21 at 15:29
  • Thank you @rzlvmp, this solution worked for me. Srry to update late here – lucky Feb 28 '22 at 08:15

2 Answers2

0

Even though the exec form is recommended, in this case, since the format is complicated, a separate shell script was created and executed.

The test environment does not include the java environment, and is configured to pass arguments to exec form when running the container.

[Dockerfile]

FROM ubuntu

COPY ./entrypoint.sh /

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

[entrypoint.sh]

#!/bin/bash
echo java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=mountpath-heapdump/$POD_ID$(date +$DATE_FORMAT)_heapdump.bin -jar /app.jar

[docker build & run]

docker build -t test .
docker run --rm -e POD_ID='POD_ID' -e DATE_FORMAT='%Y-%m-%d_%H-%M-%S' test

output is...

root@DESKTOP-6Q87NVH:/tmp/test# docker run --rm -e POD_ID='POD_ID' -e DATE_FORMAT='%Y-%m-%d_%H-%M-%S' test
java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=mountpath-heapdump/POD_ID2021-11-03_15-02-22_heapdump.bin -jar /app.jar
JongWon Lee
  • 145
  • 6
0

Answer provided by @rzlvmp worked for me.

You may try to run java inside shell ENTRYPOINT ["bash", "-c", "java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=mountpath-heapdump/$MY_POD_ID$(date +'%Y-%m-%d_%H-%M-%S')_heapdump.bin -jar /app.jar"]

lucky
  • 331
  • 6
  • 14