diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py index 7eea7888059..2f5cb8690d9 100644 --- a/cloud/docker/docker.py +++ b/cloud/docker/docker.py @@ -174,7 +174,8 @@ options: default: null detach: description: - - Enable detached mode to leave the container running in background. + - Enable detached mode to leave the container running in background. If + disabled, fail unless the process exits cleanly. default: true state: description: @@ -1258,6 +1259,13 @@ class DockerManager(object): self.client.start(i['Id'], **params) self.increment_counter('started') + if not self.module.params.get('detach'): + status = self.client.wait(i['Id']) + if status != 0: + output = self.client.logs(i['Id'], stdout=True, stderr=True, + stream=False, timestamps=False) + self.module.fail_json(status=status, msg=output) + def stop_containers(self, containers): for i in containers: self.client.stop(i['Id'])