Docker events when container automatically restarted

I’m trying to use the API to capture automatic restart events. It seems there is no unique event for this specific case. Instead you need to expect a pattern:

    # restart - die, start, restart
    # stop - die, stop
    # start - start
    # abend - die, start

In other words you need to track the sequence die, start and then check there is no restart event in order to know that the container was automatically restarted, instead of just restarted with the restart command.

Is there any easier way that I am missing ? If not could we have something like an autorestart event ? It would be nice to be able to trap “the container died” rather than it stopped succinctly.

1 Like

the events record what Docker API calls where made, so yes, its accurate - and as you note, not entirely satisfactory.

worse, I did my test with docker run --rm -it busyboxsh - and so once I exited the container, all its meta info like exit code was gone too - restarting that container is weird (it works)

I think you’ll need to make a Proposal, in github, or (ideally) a pull request.

one other thing that can be useful, is docker wait CONTAINER - as that will tell you the return code of your container. I do wonder if that too would be useful to have in the events log

Raised issue: