docker-py
docker-py copied to clipboard
`exec_run` with `demux=True`: output is `None` instead of empty `bytes`
When calling exec_run
with demux=True
, the documentation states that a pair of bytes
is returned.
However, if no standard output (or no standard error) is produced, then the corresponding tuple entry is None
instead of an empty bytes
(b''
).
Minimum working example:
import docker
client = docker.from_env()
container = client.containers.run("alpine:latest", detach=True, tty=True)
container.exec_run(("sh", "-c", "echo out >&1"), demux=True) # ExecResult(exit_code=0, output=(b'out\n', None))
container.exec_run(("sh", "-c", "echo err >&2"), demux=True) # ExecResult(exit_code=0, output=(None, b'err\n'))
The expected behaviour is that both tuple entries are always bytes
. Alternatively, the possibility of returning None
should be documented clearly!
Yes, I checked that in documentation here and it seems very easily solvable as below:
+ exec_output = tuple(b'' if x is None else x for x in exec_output)