Skip to content

Commit 3cd66b6

Browse files
committed
Merge pull request #719 from docker/allow-path-in-host
Allow docker host (base_url) to contain a path
2 parents 139850f + adb2d01 commit 3cd66b6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docker/utils/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def parse_host(addr):
232232
proto = "http+unix"
233233
host = DEFAULT_HTTP_HOST
234234
port = None
235+
path = ''
235236
if not addr or addr.strip() == 'unix://':
236237
return DEFAULT_UNIX_SOCKET
237238

@@ -270,8 +271,12 @@ def parse_host(addr):
270271
if host_parts[0]:
271272
host = host_parts[0]
272273

274+
port = host_parts[1]
275+
if '/' in port:
276+
port, path = port.split('/', 1)
277+
path = '/{0}'.format(path)
273278
try:
274-
port = int(host_parts[1])
279+
port = int(port)
275280
except Exception:
276281
raise errors.DockerException(
277282
"Invalid port: %s", addr
@@ -285,7 +290,7 @@ def parse_host(addr):
285290

286291
if proto == "http+unix":
287292
return "{0}://{1}".format(proto, host)
288-
return "{0}://{1}:{2}".format(proto, host, port)
293+
return "{0}://{1}:{2}{3}".format(proto, host, port, path)
289294

290295

291296
def parse_devices(devices):

tests/utils_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ def test_parse_host(self):
7272
'': 'http+unix://var/run/docker.sock',
7373
None: 'http+unix://var/run/docker.sock',
7474
'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
75-
'unix://': 'http+unix://var/run/docker.sock'
75+
'unix://': 'http+unix://var/run/docker.sock',
76+
'somehost.net:80/service/swarm': (
77+
'http://somehost.net:80/service/swarm'
78+
),
7679
}
7780

7881
for host in invalid_hosts:

0 commit comments

Comments
 (0)