diff --git a/fig/cli/command.py b/fig/cli/command.py index c60020d750..abf087628a 100644 --- a/fig/cli/command.py +++ b/fig/cli/command.py @@ -11,7 +11,7 @@ import yaml from ..project import Project from .docopt_command import DocoptCommand from .formatter import Formatter -from .utils import cached_property, docker_url +from .utils import cached_property, docker_url, call_silently, is_mac, is_ubuntu from .errors import UserError log = logging.getLogger(__name__) @@ -23,7 +23,29 @@ class Command(DocoptCommand): try: super(Command, self).dispatch(*args, **kwargs) except ConnectionError: - raise UserError(""" + if call_silently(['which', 'docker']) != 0: + if is_mac(): + raise UserError(""" +Couldn't connect to Docker daemon. You might need to install docker-osx: + +https://github.com/noplay/docker-osx +""") + elif is_ubuntu(): + raise UserError(""" +Couldn't connect to Docker daemon. You might need to install Docker: + +http://docs.docker.io/en/latest/installation/ubuntulinux/ +""") + else: + raise UserError(""" +Couldn't connect to Docker daemon. You might need to install Docker: + +http://docs.docker.io/en/latest/installation/ +""") + elif call_silently(['which', 'docker-osx']) == 0: + raise UserError("Couldn't connect to Docker daemon - you might need to run `docker-osx shell`.") + else: + raise UserError(""" Couldn't connect to Docker daemon at %s - is it running? If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable. diff --git a/fig/cli/utils.py b/fig/cli/utils.py index 3116df98bd..64b2ea383e 100644 --- a/fig/cli/utils.py +++ b/fig/cli/utils.py @@ -4,6 +4,8 @@ from __future__ import division import datetime import os import socket +import subprocess +import platform from .errors import UserError @@ -108,3 +110,19 @@ def split_buffer(reader, separator): if len(buffered) > 0: yield buffered + + +def call_silently(*args, **kwargs): + """ + Like subprocess.call(), but redirects stdout and stderr to /dev/null. + """ + with open(os.devnull, 'w') as shutup: + return subprocess.call(*args, stdout=shutup, stderr=shutup, **kwargs) + + +def is_mac(): + return platform.system() == 'Darwin' + + +def is_ubuntu(): + return platform.system() == 'Linux' and platform.linux_distribution()[0] == 'Ubuntu'