diff options
author | Aanand Prasad <aanand.prasad@gmail.com> | 2016-10-14 17:30:10 +0100 |
---|---|---|
committer | Aanand Prasad <aanand.prasad@gmail.com> | 2016-10-14 17:31:21 +0100 |
commit | 925915eb2535a069d3eefe4c14d35e5964182ff9 (patch) | |
tree | 48fc955dde99423bd5460ef4689ee2c21a891f5f /compose/cli | |
parent | 8314a48a2e96a0e34e913fb6b3a2973f1bceec5a (diff) |
Show clear error when docker binary can't be found
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
Diffstat (limited to 'compose/cli')
-rw-r--r-- | compose/cli/main.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/compose/cli/main.py b/compose/cli/main.py index cbbb1325..58b95c2f 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -6,6 +6,7 @@ import contextlib import functools import json import logging +import pipes import re import subprocess import sys @@ -415,7 +416,7 @@ class TopLevelCommand(object): tty = not options["-T"] if IS_WINDOWS_PLATFORM and not detach: - args = ["docker", "exec"] + args = ["exec"] if options["-d"]: args += ["--detach"] @@ -434,7 +435,7 @@ class TopLevelCommand(object): args += [container.id] args += command - sys.exit(subprocess.call(args)) + sys.exit(call_docker(args)) create_exec_options = { "privileged": options["--privileged"], @@ -982,8 +983,7 @@ def run_one_off_container(container_options, project, service, options): try: try: if IS_WINDOWS_PLATFORM: - args = ["docker", "start", "--attach", "--interactive", container.id] - exit_code = subprocess.call(args) + exit_code = call_docker(["start", "--attach", "--interactive", container.id]) else: operation = RunOperation( project.client, @@ -1060,3 +1060,15 @@ def exit_if(condition, message, exit_code): if condition: log.error(message) raise SystemExit(exit_code) + + +def call_docker(args): + try: + executable_path = subprocess.check_output(["which", "docker"]).strip() + except subprocess.CalledProcessError: + raise UserError(errors.docker_not_found_msg("Couldn't find `docker` binary.")) + + args = [executable_path] + args + log.debug(" ".join(map(pipes.quote, args))) + + return subprocess.call(args) |