Support -H=host notation for interactive run/execs

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-03-26 14:25:31 -07:00
parent 7d68d4bb44
commit cbb9bff924
3 changed files with 16 additions and 1 deletions

View File

@ -1418,7 +1418,7 @@ def call_docker(args, dockeropts):
if verify:
tls_options.append('--tlsverify')
if host:
tls_options.extend(['--host', host])
tls_options.extend(['--host', host.lstrip('=')])
args = [executable_path] + tls_options + args
log.debug(" ".join(map(pipes.quote, args)))

View File

@ -177,6 +177,13 @@ class CLITestCase(DockerClientTestCase):
returncode=0
)
def test_shorthand_host_opt_interactive(self):
self.dispatch(
['-H={0}'.format(os.environ.get('DOCKER_HOST', 'unix://')),
'run', 'another', 'ls'],
returncode=0
)
def test_host_not_reachable(self):
result = self.dispatch(['-H=tcp://doesnotexist:8000', 'ps'], returncode=1)
assert "Couldn't connect to Docker daemon" in result.stderr

View File

@ -154,3 +154,11 @@ class TestCallDocker(object):
assert fake_call.call_args[0][0] == [
'docker', '--host', 'tcp://mydocker.net:2333', 'ps'
]
def test_with_host_option_shorthand_equal(self):
with mock.patch('subprocess.call') as fake_call:
call_docker(['ps'], {'--host': '=tcp://mydocker.net:2333'})
assert fake_call.call_args[0][0] == [
'docker', '--host', 'tcp://mydocker.net:2333', 'ps'
]