2

I have a process in a docker container that is supposed to log a thread dump (on stdout) when shut down. However when docker stop is called on it, no output happens.

It seems that either the process doesn't receive the TERM signal or the output is detached before the shutdown is complete.

I'm using only a CMD (no ENTRYPOINT) in my Dockerfile:

CMD java ${MY_JAVA_OPTS} my-uberjar.jar 

How do I get output on shutdown working?

1 Answer 1

1

The entry point of the docker container is a shell calling that CMD, because it is in shell form.

This form of calling doesn't propagate signals, however.

You need to call the process using exec, which can be done by either using the exec form:

CMD ["java", "-Doption=value", "my-uberjar.jar"] 

or by using exec explicitly:

CMD exec java ${MY_JAVA_OPTS} my-uberjar.jar 

This results in the shell replacing itself with the started process, which then receives the signals.

The exec form doesn't do shell expansion, though (because there is no shell), so if you need that, you'd have to wrap a shell invocation and exec again:

CMD ["/bin/sh", "-c", "exec", "java", "${MY_JAVA_OPTS}", ... 

or use the shell form with exec as above.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.