I am attempting to check if (and handle all edge cases for) a container has been stopped or exited in an unclean state. I am using the 'State'
block returned by docker inspect <container>
to attempt to resolve this.
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-03-01T18:56:19.541980678Z",
"FinishedAt": "2018-03-01T18:56:24.618264625Z"
},
I know the 'ExitCode'
of a stopped container will be 137
, but there's a lot of other information there. Will filtering on State.ExitCode == 137
be enough to filter for stopped instances?
EDIT: I should mention the reason why I am attempting to do this instead of using pause
and unpause
to manage my containers is that I want and active/standby arrangement of containers with port bindings. A container in paused
state still maintains its port bindings which I need released when it is in standby
state.
To get stopped container:
docker ps -f status=exited -f name=$container_name
See docker ps
filtering documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With