docker / docker/docker-py

exec_run does not produce exit_code when both stderr and stdout are False

Open
#2,450 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

See below for an example of this behaviour. Essentially, I would like to be able to run a code, ignore its output, and just check its exit code. A workaround is to redirect the stderr/stdout to /dev/null in this case (i.e., "echo 'hello world' > /dev/null 2> /dev/null), but I would expect docker-py to be able to handle this use case without the need for manual instrumentation.

client = docker.from_env()
container = client.containers.run(
    'alpine', "sh -c 'sleep 60'", detach=True)

exec_output = \
    container.exec_run("echo 'hello world'")
print(exec_output)
# ExecResult(exit_code=0, output=b'hello world\n')

exec_output_without_stdout = \
    container.exec_run("echo 'hello world'", stdout=False)
print(exec_output_without_stdout)
# ExecResult(exit_code=0, output=b'')

exec_output_without_stderr = \
    container.exec_run("echo 'hello world'", stderr=False)
print(exec_output_without_stderr)
# ExecResult(exit_code=0, output=b'hello world\n')

exec_output_without_stdout_or_stderr = \
    container.exec_run("echo 'hello world'", stdout=False, stderr=False)
print(exec_output_without_stdout_or_stderr)
# ExecResult(exit_code=None, output=b'')

container.remove(force=True)

For reference, here are some details about my environment:

(docker-py) $ docker --version
Docker version 19.03.1-ce, build 74b1e89e8a
(docker-py) $ python --version
Python 3.7.4
(docker-py) $ pip list
Package          Version  
---------------- ---------
certifi          2019.9.11
chardet          3.0.4    
docker           4.1.0    
idna             2.8      
pip              19.3.1   
requests         2.22.0   
setuptools       41.4.0   
six              1.12.0   
urllib3          1.25.6   
websocket-client 0.56.0   
wheel            0.33.6  

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the exec_run entry point and trace how stdout and stderr settings affect the returned ExecResult. Add a regression test for both streams disabled, verifying that the exit_code is still reported while output remains empty.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.