result.wait()
should wait for the container to run to completion, then return its exit code.
However, you'll probably hit some trouble with this since you specify auto_remove=True
but do not specify detach=True
. run()
without detach=True
will run the container to completion, then the auto_remove=True
option will delete the container, and at that point the status code doesn't exist any more. You might split these steps up explicitly:
client = docker.from_env()
container = client.containers.run(
image="my-prog-image:latest",
command=["/etc/my-prog/configs.ini"],
detach=True,
)
result = container.wait()
container.remove()
(In Docker CLI terms, you've done docker run --rm ...
and then are trying to find the container's result with docker ps -a
, but the container is gone; I suggest changing it to docker run -d ...
without --rm
, checking the docker ps
output, and then manually docker rm
the container. Actually, there's even a docker wait
CLI command but it's rarely used.)