mirror of
https://github.com/docker/compose.git
synced 2025-07-22 21:24:38 +02:00
Check default socket and localhost:4243 for Docker daemon
This commit is contained in:
parent
ebf9bf387c
commit
ff65a3e1b0
@ -3,11 +3,13 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import yaml
|
||||
import socket
|
||||
|
||||
from ..project import Project
|
||||
from .docopt_command import DocoptCommand
|
||||
from .formatter import Formatter
|
||||
from .utils import cached_property
|
||||
from .errors import UserError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -16,8 +18,26 @@ class Command(DocoptCommand):
|
||||
def client(self):
|
||||
if os.environ.get('DOCKER_URL'):
|
||||
return Client(os.environ['DOCKER_URL'])
|
||||
else:
|
||||
return Client()
|
||||
|
||||
socket_path = '/var/run/docker.sock'
|
||||
tcp_host = '127.0.0.1'
|
||||
tcp_port = 4243
|
||||
|
||||
if os.path.exists(socket_path):
|
||||
return Client('unix://%s' % socket_path)
|
||||
|
||||
try:
|
||||
s = socket.socket()
|
||||
s.connect((tcp_host, tcp_port))
|
||||
s.close()
|
||||
return Client('http://%s:%s' % (tcp_host, tcp_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))
|
||||
|
||||
@cached_property
|
||||
def project(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user