Docker-py: How to get the exit code of a container?

Created on 31 Dec 2018  路  2Comments  路  Source: docker/docker-py

Hi, this is more of a question than an issue.

Once I have a Container object of a container that exited ( possibly from client.run() ), how do I get the exit_code of that container? I looked at the documentation, it points me to container.status attribute, but it only gives a descriptive status of the container.

I can always do a subprocess.Popen and do this

docker inspect 61c6 --format='{{.State.ExitCode}}'

If the same data is available through something like container.exit_code it would be helpful.
Thanks :smile:

kinquestion

Most helpful comment

container.attrs['State']['ExitCode']

Make sure to call container.reload() first.

All 2 comments

container.attrs['State']['ExitCode']

Make sure to call container.reload() first.

Thanks @shin- It works. Just a humble suggestion, may add this to documentation?

Closing this.

Was this page helpful?
0 / 5 - 0 ratings