Inspecting stdout of a rc!=0 container called with run(detach=False)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
Trying to run a container, I was getting a non-zero return code (because the container was missing a variable for the process inside the container to complete successfully), and was wondering how to inspect stdout and stderr of the container. The following is my attempt:
import docker
client = docker.from_env()
try:
out, err = client.containers.run(image="some_image_that_fails", stdout=True, stderr=True)
except Exception as e:
print(e)
Running like this, I only get stderr, not stdout though.
Is this intended? It's perhaps a philosofical question whether the stdout should be returned when there's an error... I also figured out that you can get both if you run with detach=True - but should this be necessary?
I believe the responsible line is this line in models/container.py where the output that is part of the exceptions arguments raised for non-zero return code is set to only stderr.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read models/containers.py at the linked line where the non-zero return-code exception output is set. Compare run(detach=False) with detach=True and verify that a failing container makes both stdout and stderr available through the exception; no test file is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100