Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker/clientbase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import struct
import sys

import requests
import requests.exceptions
Expand Down Expand Up @@ -31,7 +32,7 @@ def __init__(self, base_url=None, version=None,

self._auth_configs = auth.load_config()

base_url = utils.parse_host(base_url)
base_url = utils.parse_host(base_url, sys.platform)
if base_url.startswith('http+unix://'):
self._custom_adapter = unixconn.UnixAdapter(base_url, timeout)
self.mount('http+docker://', self._custom_adapter)
Expand Down
6 changes: 5 additions & 1 deletion docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ def parse_repository_tag(repo):
# fd:// protocol unsupported (for obvious reasons)
# Added support for http and https
# Protocol translation: tcp -> http, unix -> http+unix
def parse_host(addr):
def parse_host(addr, platform=None):
proto = "http+unix"
host = DEFAULT_HTTP_HOST
port = None
path = ''

if not addr and platform == 'win32':
addr = '{0}:{1}'.format(DEFAULT_HTTP_HOST, 2375)

if not addr or addr.strip() == 'unix://':
return DEFAULT_UNIX_SOCKET

Expand Down
16 changes: 12 additions & 4 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ def test_parse_host(self):
'tcp://:7777': 'http://127.0.0.1:7777',
'http://:7777': 'http://127.0.0.1:7777',
'https://kokia.jp:2375': 'https://kokia.jp:2375',
'': 'http+unix://var/run/docker.sock',
None: 'http+unix://var/run/docker.sock',
'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
'unix://': 'http+unix://var/run/docker.sock',
'somehost.net:80/service/swarm': (
Expand All @@ -90,10 +88,20 @@ def test_parse_host(self):

for host in invalid_hosts:
with pytest.raises(DockerException):
parse_host(host)
parse_host(host, None)

for host, expected in valid_hosts.items():
self.assertEqual(parse_host(host), expected, msg=host)
self.assertEqual(parse_host(host, None), expected, msg=host)

def test_parse_host_empty_value(self):
unix_socket = 'http+unix://var/run/docker.sock'
tcp_port = 'http://127.0.0.1:2375'

for val in [None, '']:
for platform in ['darwin', 'linux2', None]:
assert parse_host(val, platform) == unix_socket

assert parse_host(val, 'win32') == tcp_port

def test_kwargs_from_env_empty(self):
os.environ.update(DOCKER_HOST='',
Expand Down