question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get exec_run exit_code?

See original GitHub issue

Hi,

I create an ubuntu container and then running exec_run later. But I can not get the exit_code. exec_run just return output bytecode. I don’t know whether the executing result is successful or not.

>>> import docker
>>> client = docker.from_env()
>>> container = client.containers.run('ubuntu', command=['/bin/bash'], tty=True, detach=True)
>>> container.exec_run(['not_exist'])
b'rpc error: code = 2 desc = oci runtime error: exec failed: exec: "not_exist": executable file not found in $PATH\r\n'
>>>

I can use APIClient.exec_create(), APIClient.exec_start() and APIClient.exec_inspect() to achieve the goal. Is there has any high level api to use?

Thanks for your reply.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
funkyfuturecommented, Jun 25, 2017

imo, with the next breaking release Container.exec_run should return two values in that order: the exit code and the tty output, if stream is False.

4reactions
ClaytonSmithcommented, Aug 21, 2019

Hope this helps:

exec_handle = docker_client.exec_create(...)
stream = docker_client.exec_start(exec_handle, stream=True)

# Stream handling

docker_client.exec_inspect(exec_handler['Id']).get('ExitCode') 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Get exit code - Go - Stack Overflow
It's easy to determine if the exit code was 0 or something else. In the first case, cmd.Wait() will return nil (unless there...
Read more >
Null exitCode ispecting a running exec · Issue #748 ... - GitHub
Im getting a JsonMappingException : Instantiation of [simple type, class com.spotify.docker.client.messages.ExecState] value failed: Null ...
Read more >
Ubuntu Manpage: docker-container-exec - Run a command in ...
docker-container-exec - Run a command in a running container ... The exit code from docker exec gives information about why the container failed...
Read more >
Get exit code from command "exec" - Unix Stack Exchange
If you want your shell to interpret the exit code of a program, you cannot use exec to do it. Just run the...
Read more >
Resource Type: exec - Puppet
This exec would only run if every command in the array has an exit code of 0 (success). (↑ Back to exec attributes)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found