Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to check wether an exec_run has finished? #3138

Open
Pymann opened this issue Jun 5, 2023 · 2 comments
Open

Any way to check wether an exec_run has finished? #3138

Pymann opened this issue Jun 5, 2023 · 2 comments

Comments

@Pymann
Copy link

Pymann commented Jun 5, 2023

you know its possible to receive a generator from an exec-run. I can print the stream if there is any next item... but when to end, how could I ever know, wether an exec-run has finished?

@naufalafif
Copy link

this might work, using exec_inspect from low-level API

import docker

client = docker.from_env()

# Start the exec instance
exec_instance = client.containers.get('my_container').exec_run('ls')

# Check the status of the exec instance
exec_status = client.api.exec_inspect(exec_instance.id).get('Running')

if exec_status:
    print('Exec instance is still running')
else:
    print('Exec instance has finished')

@fmelihh
Copy link

fmelihh commented Jun 15, 2023

It could be useful.

import docker
 succeed_info = (
        docker.from_env()
        .containers.get("container")
        .exec_run("some command")
        .exit_code
    )

  if succeed_info != 0:
      raise Exception("Error")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants