diff --git a/fig/cli/utils.py b/fig/cli/utils.py index 1094b5e77b..a1ff0c008c 100644 --- a/fig/cli/utils.py +++ b/fig/cli/utils.py @@ -83,21 +83,29 @@ def docker_url(): return os.environ['DOCKER_URL'] socket_path = '/var/run/docker.sock' + tcp_hosts = [ + ('localdocker', 4243), + ('127.0.0.1', 4243), + ] tcp_host = '127.0.0.1' tcp_port = 4243 if os.path.exists(socket_path): return 'unix://%s' % socket_path - try: - s = socket.socket() - s.connect((tcp_host, tcp_port)) - s.close() - return 'http://%s:%s' % (tcp_host, tcp_port) - except: - pass + for host, port in tcp_hosts: + try: + s = socket.create_connection((host, port), timeout=1) + s.close() + return 'http://%s:%s' % (host, port) + except: + pass raise UserError(""" - Couldn't find Docker daemon - tried %s and %s:%s. - If it's running elsewhere, specify a url with DOCKER_URL. - """ % (socket_path, tcp_host, tcp_port)) +Couldn't find Docker daemon - tried: + +unix://%s +%s + +If it's running elsewhere, specify a url with DOCKER_URL. + """ % (socket_path, '\n'.join('tcp://%s:%s' % h for h in tcp_hosts)))