diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 4d218692..1cfc8acc 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -22,8 +22,8 @@ import tarfile
 import tempfile
 import warnings
 from distutils.version import StrictVersion
-from fnmatch import fnmatch
 from datetime import datetime
+from fnmatch import fnmatch
 
 import requests
 import six
@@ -33,6 +33,10 @@ from .. import errors
 from .. import tls
 from .types import Ulimit, LogConfig
 
+if six.PY2:
+    from urllib import splitnport
+else:
+    from urllib.parse import splitnport
 
 DEFAULT_HTTP_HOST = "127.0.0.1"
 DEFAULT_UNIX_SOCKET = "http+unix://var/run/docker.sock"
@@ -387,7 +391,6 @@ def parse_repository_tag(repo_name):
 # Protocol translation: tcp -> http, unix -> http+unix
 def parse_host(addr, is_win32=False, tls=False):
     proto = "http+unix"
-    host = DEFAULT_HTTP_HOST
     port = None
     path = ''
 
@@ -427,32 +430,27 @@ def parse_host(addr, is_win32=False, tls=False):
             )
         proto = "https" if tls else "http"
 
-    if proto != "http+unix" and ":" in addr:
-        host_parts = addr.split(':')
-        if len(host_parts) != 2:
-            raise errors.DockerException(
-                "Invalid bind address format: {0}".format(addr)
-            )
-        if host_parts[0]:
-            host = host_parts[0]
+    if proto in ("http", "https"):
+        address_parts = addr.split('/', 1)
+        host = address_parts[0]
+        if len(address_parts) == 2:
+            path = '/' + address_parts[1]
+        host, port = splitnport(host)
 
-        port = host_parts[1]
-        if '/' in port:
-            port, path = port.split('/', 1)
-            path = '/{0}'.format(path)
-        try:
-            port = int(port)
-        except Exception:
+        if port is None:
             raise errors.DockerException(
                 "Invalid port: {0}".format(addr)
             )
 
-    elif proto in ("http", "https") and ':' not in addr:
-        raise errors.DockerException(
-            "Bind address needs a port: {0}".format(addr))
+        if not host:
+            host = DEFAULT_HTTP_HOST
     else:
         host = addr
 
+    if proto in ("http", "https") and port == -1:
+        raise errors.DockerException(
+            "Bind address needs a port: {0}".format(addr))
+
     if proto == "http+unix" or proto == 'npipe':
         return "{0}://{1}".format(proto, host)
     return "{0}://{1}:{2}{3}".format(proto, host, port, path)

diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py
index 68484fe5..0f7a58c9 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -404,10 +404,18 @@ class ParseHostTest(base.BaseTestCase):
             'https://kokia.jp:2375': 'https://kokia.jp:2375',
             'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
             'unix://': 'http+unix://var/run/docker.sock',
+            '12.234.45.127:2375/docker/engine': (
+                'http://12.234.45.127:2375/docker/engine'
+            ),
             'somehost.net:80/service/swarm': (
                 'http://somehost.net:80/service/swarm'
             ),
             'npipe:////./pipe/docker_engine': 'npipe:////./pipe/docker_engine',
+            '[fd12::82d1]:2375': 'http://[fd12::82d1]:2375',
+            'https://[fd12:5672::12aa]:1090': 'https://[fd12:5672::12aa]:1090',
+            '[fd12::82d1]:2375/docker/engine': (
+                'http://[fd12::82d1]:2375/docker/engine'
+            ),
         }
 
         for host in invalid_hosts:
@@ -415,7 +423,7 @@ class ParseHostTest(base.BaseTestCase):
                 parse_host(host, None)
 
         for host, expected in valid_hosts.items():
-            self.assertEqual(parse_host(host, None), expected, msg=host)
+            assert parse_host(host, None) == expected
 
     def test_parse_host_empty_value(self):
         unix_socket = 'http+unix://var/run/docker.sock'

Support IPv6 addresses in DOCKER_HOST
Raised in https://github.com/docker/compose/issues/2879.

See https://github.com/docker/docker/pull/16950 for the Engine implementation.
tests/unit/utils_test.py::ParseHostTest::test_parse_host
tests/unit/utils_test.py::HostConfigTest::test_create_endpoint_config_with_aliases tests/unit/utils_test.py::HostConfigTest::test_create_host_config_invalid_cpu_cfs_types tests/unit/utils_test.py::HostConfigTest::test_create_host_config_no_options tests/unit/utils_test.py::HostConfigTest::test_create_host_config_no_options_newer_api_version tests/unit/utils_test.py::HostConfigTest::test_create_host_config_with_blkio_constraints tests/unit/utils_test.py::HostConfigTest::test_create_host_config_with_cpu_period tests/unit/utils_test.py::HostConfigTest::test_create_host_config_with_cpu_quota tests/unit/utils_test.py::HostConfigTest::test_create_host_config_with_oom_kill_disable tests/unit/utils_test.py::HostConfigTest::test_create_host_config_with_oom_score_adj tests/unit/utils_test.py::HostConfigTest::test_create_host_config_with_shm_size tests/unit/utils_test.py::HostConfigTest::test_create_host_config_with_shm_size_in_mb tests/unit/utils_test.py::UlimitTest::test_create_host_config_dict_ulimit tests/unit/utils_test.py::UlimitTest::test_create_host_config_dict_ulimit_capitals tests/unit/utils_test.py::UlimitTest::test_create_host_config_obj_ulimit tests/unit/utils_test.py::UlimitTest::test_ulimit_invalid_type tests/unit/utils_test.py::LogConfigTest::test_create_host_config_dict_logconfig tests/unit/utils_test.py::LogConfigTest::test_create_host_config_obj_logconfig tests/unit/utils_test.py::LogConfigTest::test_logconfig_invalid_config_type tests/unit/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_alternate_env tests/unit/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_empty tests/unit/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_no_cert_path tests/unit/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_tls tests/unit/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_tls_verify_false tests/unit/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_tls_verify_false_no_cert tests/unit/utils_test.py::ConverVolumeBindsTest::test_convert_volume_binds_compact tests/unit/utils_test.py::ConverVolumeBindsTest::test_convert_volume_binds_complete tests/unit/utils_test.py::ConverVolumeBindsTest::test_convert_volume_binds_empty tests/unit/utils_test.py::ConverVolumeBindsTest::test_convert_volume_binds_list tests/unit/utils_test.py::ConverVolumeBindsTest::test_convert_volume_binds_no_mode tests/unit/utils_test.py::ConverVolumeBindsTest::test_convert_volume_binds_unicode_bytes_input tests/unit/utils_test.py::ConverVolumeBindsTest::test_convert_volume_binds_unicode_unicode_input tests/unit/utils_test.py::ParseEnvFileTest::test_parse_env_file_commented_line tests/unit/utils_test.py::ParseEnvFileTest::test_parse_env_file_invalid_line tests/unit/utils_test.py::ParseEnvFileTest::test_parse_env_file_proper tests/unit/utils_test.py::ParseEnvFileTest::test_parse_env_file_with_equals_character tests/unit/utils_test.py::ParseHostTest::test_parse_host_empty_value tests/unit/utils_test.py::ParseHostTest::test_parse_host_tls tests/unit/utils_test.py::ParseHostTest::test_parse_host_tls_tcp_proto tests/unit/utils_test.py::ParseRepositoryTagTest::test_index_image_no_tag tests/unit/utils_test.py::ParseRepositoryTagTest::test_index_image_sha tests/unit/utils_test.py::ParseRepositoryTagTest::test_index_image_tag tests/unit/utils_test.py::ParseRepositoryTagTest::test_index_user_image_no_tag tests/unit/utils_test.py::ParseRepositoryTagTest::test_index_user_image_tag tests/unit/utils_test.py::ParseRepositoryTagTest::test_private_reg_image_no_tag tests/unit/utils_test.py::ParseRepositoryTagTest::test_private_reg_image_sha tests/unit/utils_test.py::ParseRepositoryTagTest::test_private_reg_image_tag tests/unit/utils_test.py::ParseDeviceTest::test_dict tests/unit/utils_test.py::ParseDeviceTest::test_full_string_definition tests/unit/utils_test.py::ParseDeviceTest::test_hybrid_list tests/unit/utils_test.py::ParseDeviceTest::test_partial_string_definition tests/unit/utils_test.py::ParseDeviceTest::test_permissionless_string_definition tests/unit/utils_test.py::ParseBytesTest::test_parse_bytes_float tests/unit/utils_test.py::ParseBytesTest::test_parse_bytes_invalid tests/unit/utils_test.py::ParseBytesTest::test_parse_bytes_maxint tests/unit/utils_test.py::ParseBytesTest::test_parse_bytes_valid tests/unit/utils_test.py::UtilsTest::test_convert_filters tests/unit/utils_test.py::UtilsTest::test_create_ipam_config tests/unit/utils_test.py::UtilsTest::test_decode_json_header tests/unit/utils_test.py::SplitCommandTest::test_split_command_with_unicode tests/unit/utils_test.py::PortsTest::test_build_port_bindings_with_matching_internal_port_ranges tests/unit/utils_test.py::PortsTest::test_build_port_bindings_with_matching_internal_ports tests/unit/utils_test.py::PortsTest::test_build_port_bindings_with_nonmatching_internal_port_ranges tests/unit/utils_test.py::PortsTest::test_build_port_bindings_with_nonmatching_internal_ports tests/unit/utils_test.py::PortsTest::test_build_port_bindings_with_one_port tests/unit/utils_test.py::PortsTest::test_build_port_bindings_with_port_range tests/unit/utils_test.py::PortsTest::test_host_only_with_colon tests/unit/utils_test.py::PortsTest::test_non_matching_length_port_ranges tests/unit/utils_test.py::PortsTest::test_port_and_range_invalid tests/unit/utils_test.py::PortsTest::test_port_only_with_colon tests/unit/utils_test.py::PortsTest::test_split_port_invalid tests/unit/utils_test.py::PortsTest::test_split_port_no_host_port tests/unit/utils_test.py::PortsTest::test_split_port_range_no_host_port tests/unit/utils_test.py::PortsTest::test_split_port_range_with_host_ip_no_port tests/unit/utils_test.py::PortsTest::test_split_port_range_with_host_port tests/unit/utils_test.py::PortsTest::test_split_port_range_with_protocol tests/unit/utils_test.py::PortsTest::test_split_port_with_host_ip tests/unit/utils_test.py::PortsTest::test_split_port_with_host_ip_no_port tests/unit/utils_test.py::PortsTest::test_split_port_with_host_port tests/unit/utils_test.py::PortsTest::test_split_port_with_protocol tests/unit/utils_test.py::ExcludePathsTest::test_directory tests/unit/utils_test.py::ExcludePathsTest::test_directory_with_single_exception tests/unit/utils_test.py::ExcludePathsTest::test_directory_with_subdir_exception tests/unit/utils_test.py::ExcludePathsTest::test_directory_with_trailing_slash tests/unit/utils_test.py::ExcludePathsTest::test_directory_with_wildcard_exception tests/unit/utils_test.py::ExcludePathsTest::test_exclude_custom_dockerfile tests/unit/utils_test.py::ExcludePathsTest::test_exclude_dockerfile_child tests/unit/utils_test.py::ExcludePathsTest::test_exclude_dockerfile_dockerignore tests/unit/utils_test.py::ExcludePathsTest::test_no_dupes tests/unit/utils_test.py::ExcludePathsTest::test_no_excludes tests/unit/utils_test.py::ExcludePathsTest::test_question_mark tests/unit/utils_test.py::ExcludePathsTest::test_single_filename tests/unit/utils_test.py::ExcludePathsTest::test_single_filename_leading_dot_slash tests/unit/utils_test.py::ExcludePathsTest::test_single_filename_trailing_slash tests/unit/utils_test.py::ExcludePathsTest::test_single_subdir_single_filename tests/unit/utils_test.py::ExcludePathsTest::test_single_subdir_wildcard_filename tests/unit/utils_test.py::ExcludePathsTest::test_single_subdir_with_path_traversal tests/unit/utils_test.py::ExcludePathsTest::test_subdirectory tests/unit/utils_test.py::ExcludePathsTest::test_wildcard_exclude tests/unit/utils_test.py::ExcludePathsTest::test_wildcard_filename_end tests/unit/utils_test.py::ExcludePathsTest::test_wildcard_filename_start tests/unit/utils_test.py::ExcludePathsTest::test_wildcard_subdir_single_filename tests/unit/utils_test.py::ExcludePathsTest::test_wildcard_subdir_wildcard_filename tests/unit/utils_test.py::ExcludePathsTest::test_wildcard_with_exception tests/unit/utils_test.py::ExcludePathsTest::test_wildcard_with_wildcard_exception tests/unit/utils_test.py::TarTest::test_tar_with_directory_symlinks tests/unit/utils_test.py::TarTest::test_tar_with_empty_directory tests/unit/utils_test.py::TarTest::test_tar_with_excludes tests/unit/utils_test.py::TarTest::test_tar_with_file_symlinks