16

I'm trying to find the history of container restarts.

Of course the STATUS field on a docker ps will show the current uptime.

However if I have a container with a restart policy such as restart: unless-stopped and it's gone through several restarts - How can I check that restart/uptime history?

If the docker engine doesn't natively track this - is there a known good method to handle this?

emmdee
  • 2,187
  • 12
  • 36
  • 60

2 Answers2

23

You can view the docker events. E.g. this will show all restart events for the last hour:

docker events --filter event=restart --since=60m

For more details on docker events, see: https://docs.docker.com/engine/reference/commandline/events

BMitch
  • 5,966
  • 1
  • 25
  • 32
  • I must have missed it in the documentation. Thank you! – emmdee Apr 24 '18 at 20:03
  • `docker events` doesn't print anything for me. I had to use it with `--since` to get a result, meaning e.g.: `docker events --since 2020-01-01` (or just `--since 2020`) – MacMartin Feb 11 '22 at 09:22
  • @MacMartin I'm guessing this was intended as a comment for RobinP's almost-duplicate answer. – BMitch Feb 12 '22 at 21:24
  • 1
    See all events on your container in past hour : `docker events --filter container=my-worker --since '60m'` – Franckk Dec 08 '22 at 10:42
0

You can check with following command:

docker system events --filter event=restart

For more information : https://docs.docker.com/engine/reference/commandline/system_events

Steve Folly
  • 575
  • 3
  • 12
RobinP
  • 11
  • 1