How can I detect if a container is stopped intentionally or abnormally?

How can I detect if a container is stopped intentionally or abnormally? I.e. if we were to stop is using ‘docker stop’ where is an ‘exit code’ type output stored so we can see how it’s failed?

docker ps -a will show an exit code, and you can get it semi-programatically via docker inspect. This state stays around until you docker rm the container.

Thanks… in my test rig I see a lot of Exit 0 and 2… I can guess what 0 means, but no idea about the rest… I know apps can throw these but are there any docker exit codes that I can map these too?

Not really, these exit codes are intentionally ‘unmapped’. It allows you to build a container that acts like a shell script: it returns 0 when everything goes ok, but then a non-zero code when something goes wrong. You are free to set that exit code to whatever you think is appropriate and then to handle the exit code how you define.

If you want to follow some sort of guide for exit codes, this might be a useful reference.