shin-: @aanand Thanks, didn't know about `six.u`. PTAL?
aanand: Cool. Perhaps the first test should be rewritten so it tests byte string input on all Python versions:

```python
    def test_convert_volume_bindings_binary_input(self):
        expected = [six.u('/mnt/지연:/unicode/박:rw')]

        data = {
            b'/mnt/지연': {
                'bind': b'/unicode/박',
                'mode': 'rw'
            }
        }
        self.assertEqual(
            convert_volume_binds(data), expected
        )
```
shin-: Okay, I've tried all sorts of combination, I've settled on just separating py2 and py3 tests completely (so it's 2+2 now). On the bright side, results were consistent all along (and we have tests to prove it)!
aanand: OK, I see the rationale, but instead of entirely separate test methods, could we just switch on the Python version *inside* the method?

```python
def test_convert_volume_binds_unicode_bytes_input(self):
    if six.PY2:
        expected = [unicode('/mnt/지연:/unicode/박:rw', 'utf-8')]
        data = {
            '/mnt/지연': {
                'bind': '/unicode/박',
                'mode': 'rw'
            }
        }
    else:
        expected = ['/mnt/지연:/unicode/박:rw']
        data = {
            bytes('/mnt/지연', 'utf-8'): {
                'bind': bytes('/unicode/박', 'utf-8'),
                'mode': 'rw'
            }
        }

    self.assertEqual(convert_volume_binds(data), expected)

def test_convert_volume_binds_unicode_unicode_input(self):
    if six.PY2:
        expected = [unicode('/mnt/지연:/unicode/박:rw', 'utf-8')]
        data = {
            unicode('/mnt/지연', 'utf-8'): {
                'bind': unicode('/unicode/박', 'utf-8'),
                'mode': 'rw'
            }
        }
    else:
        expected = ['/mnt/지연:/unicode/박:rw']
        data = {
            '/mnt/지연': {
                'bind': '/unicode/박',
                'mode': 'rw'
            }
        }

    self.assertEqual(convert_volume_binds(data), expected)
```
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 36edf8de..1fce1377 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -242,6 +242,9 @@ def convert_volume_binds(binds):
 
     result = []
     for k, v in binds.items():
+        if isinstance(k, six.binary_type):
+            k = k.decode('utf-8')
+
         if isinstance(v, dict):
             if 'ro' in v and 'mode' in v:
                 raise ValueError(
@@ -249,6 +252,10 @@ def convert_volume_binds(binds):
                     .format(repr(v))
                 )
 
+            bind = v['bind']
+            if isinstance(bind, six.binary_type):
+                bind = bind.decode('utf-8')
+
             if 'ro' in v:
                 mode = 'ro' if v['ro'] else 'rw'
             elif 'mode' in v:
@@ -256,11 +263,15 @@ def convert_volume_binds(binds):
             else:
                 mode = 'rw'
 
-            result.append('{0}:{1}:{2}'.format(
-                k, v['bind'], mode
-            ))
+            result.append(
+                six.text_type('{0}:{1}:{2}').format(k, bind, mode)
+            )
         else:
-            result.append('{0}:{1}:rw'.format(k, v))
+            if isinstance(v, six.binary_type):
+                v = v.decode('utf-8')
+            result.append(
+                six.text_type('{0}:{1}:rw').format(k, v)
+            )
     return result
 
 

Create container bind volume with Unicode folder name
If bind volume folder name is Unicode, for example Japanese, It will raise exception:
Host volume and container volume both should handle Unicode.

```
  File "/home/vagrant/.local/share/virtualenvs/qnap/local/lib/python2.7/site-packages/docker/utils/utils.py", line 461, in create_host_config
    host_config['Binds'] = convert_volume_binds(binds)
  File "/home/vagrant/.local/share/virtualenvs/qnap/local/lib/python2.7/site-packages/docker/utils/utils.py", line 208, in convert_volume_binds
    k, v['bind'], mode
```
diff --git a/tests/utils_test.py b/tests/utils_test.py
index 45929f73..8ac1dcb9 100644
--- a/tests/utils_test.py
+++ b/tests/utils_test.py
@@ -1,15 +1,20 @@
+# -*- coding: utf-8 -*-
+
 import os
 import os.path
 import shutil
 import tempfile
 
+import pytest
+import six
+
 from docker.client import Client
 from docker.constants import DEFAULT_DOCKER_API_VERSION
 from docker.errors import DockerException
 from docker.utils import (
     parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
     create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
-    exclude_paths,
+    exclude_paths, convert_volume_binds,
 )
 from docker.utils.ports import build_port_bindings, split_port
 from docker.auth import resolve_repository_name, resolve_authconfig
@@ -17,7 +22,6 @@ from docker.auth import resolve_repository_name, resolve_authconfig
 from . import base
 from .helpers import make_tree
 
-import pytest
 
 TEST_CERT_DIR = os.path.join(
     os.path.dirname(__file__),
@@ -192,6 +196,89 @@ class UtilsTest(base.BaseTestCase):
         local_tempfile.close()
         return local_tempfile.name
 
+    def test_convert_volume_binds_empty(self):
+        self.assertEqual(convert_volume_binds({}), [])
+        self.assertEqual(convert_volume_binds([]), [])
+
+    def test_convert_volume_binds_list(self):
+        data = ['/a:/a:ro', '/b:/c:z']
+        self.assertEqual(convert_volume_binds(data), data)
+
+    def test_convert_volume_binds_complete(self):
+        data = {
+            '/mnt/vol1': {
+                'bind': '/data',
+                'mode': 'ro'
+            }
+        }
+        self.assertEqual(convert_volume_binds(data), ['/mnt/vol1:/data:ro'])
+
+    def test_convert_volume_binds_compact(self):
+        data = {
+            '/mnt/vol1': '/data'
+        }
+        self.assertEqual(convert_volume_binds(data), ['/mnt/vol1:/data:rw'])
+
+    def test_convert_volume_binds_no_mode(self):
+        data = {
+            '/mnt/vol1': {
+                'bind': '/data'
+            }
+        }
+        self.assertEqual(convert_volume_binds(data), ['/mnt/vol1:/data:rw'])
+
+    def test_convert_volume_binds_unicode_bytes_input(self):
+        if six.PY2:
+            expected = [unicode('/mnt/지연:/unicode/박:rw', 'utf-8')]
+
+            data = {
+                '/mnt/지연': {
+                    'bind': '/unicode/박',
+                    'mode': 'rw'
+                }
+            }
+            self.assertEqual(
+                convert_volume_binds(data), expected
+            )
+        else:
+            expected = ['/mnt/지연:/unicode/박:rw']
+
+            data = {
+                bytes('/mnt/지연', 'utf-8'): {
+                    'bind': bytes('/unicode/박', 'utf-8'),
+                    'mode': 'rw'
+                }
+            }
+            self.assertEqual(
+                convert_volume_binds(data), expected
+            )
+
+    def test_convert_volume_binds_unicode_unicode_input(self):
+        if six.PY2:
+            expected = [unicode('/mnt/지연:/unicode/박:rw', 'utf-8')]
+
+            data = {
+                unicode('/mnt/지연', 'utf-8'): {
+                    'bind': unicode('/unicode/박', 'utf-8'),
+                    'mode': 'rw'
+                }
+            }
+            self.assertEqual(
+                convert_volume_binds(data), expected
+            )
+        else:
+            expected = ['/mnt/지연:/unicode/박:rw']
+
+            data = {
+                '/mnt/지연': {
+                    'bind': '/unicode/박',
+                    'mode': 'rw'
+                }
+            }
+            self.assertEqual(
+                convert_volume_binds(data), expected
+            )
+
     def test_parse_repository_tag(self):
         self.assertEqual(parse_repository_tag("root"),
                          ("root", None))

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest
apt-get update apt-get install -y gcc
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi @ file:///croot/certifi_1671487769961/work/certifi
coverage==7.2.7
-e git+https://github.com/docker/docker-py.git@5e331a55a8e8e10354693172dce1aa63f58ebe97#egg=docker_py
exceptiongroup==1.2.2
importlib-metadata==6.7.0
iniconfig==2.0.0
packaging==24.0
pluggy==1.2.0
pytest==7.4.4
pytest-cov==4.1.0
requests==2.5.3
six==1.17.0
tomli==2.0.1
typing_extensions==4.7.1
websocket-client==0.32.0
zipp==3.15.0

name: docker-py
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - coverage==7.2.7
      - exceptiongroup==1.2.2
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - packaging==24.0
      - pluggy==1.2.0
      - pytest==7.4.4
      - pytest-cov==4.1.0
      - requests==2.5.3
      - six==1.17.0
      - tomli==2.0.1
      - typing-extensions==4.7.1
      - websocket-client==0.32.0
      - zipp==3.15.0
prefix: /opt/conda/envs/docker-py

tests/utils_test.py::UtilsTest::test_convert_volume_binds_unicode_bytes_input
tests/utils_test.py::HostConfigTest::test_create_host_config_invalid_cpu_cfs_types tests/utils_test.py::HostConfigTest::test_create_host_config_no_options tests/utils_test.py::HostConfigTest::test_create_host_config_no_options_newer_api_version tests/utils_test.py::HostConfigTest::test_create_host_config_with_cpu_period tests/utils_test.py::HostConfigTest::test_create_host_config_with_cpu_quota tests/utils_test.py::UlimitTest::test_create_host_config_dict_ulimit tests/utils_test.py::UlimitTest::test_create_host_config_dict_ulimit_capitals tests/utils_test.py::UlimitTest::test_create_host_config_obj_ulimit tests/utils_test.py::UlimitTest::test_ulimit_invalid_type tests/utils_test.py::LogConfigTest::test_create_host_config_dict_logconfig tests/utils_test.py::LogConfigTest::test_create_host_config_obj_logconfig tests/utils_test.py::LogConfigTest::test_logconfig_invalid_config_type tests/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_empty tests/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_no_cert_path tests/utils_test.py::KwargsFromEnvTest::test_kwargs_from_env_tls tests/utils_test.py::UtilsTest::test_convert_filters tests/utils_test.py::UtilsTest::test_convert_volume_binds_compact tests/utils_test.py::UtilsTest::test_convert_volume_binds_complete tests/utils_test.py::UtilsTest::test_convert_volume_binds_empty tests/utils_test.py::UtilsTest::test_convert_volume_binds_list tests/utils_test.py::UtilsTest::test_convert_volume_binds_no_mode tests/utils_test.py::UtilsTest::test_convert_volume_binds_unicode_unicode_input tests/utils_test.py::UtilsTest::test_parse_bytes tests/utils_test.py::UtilsTest::test_parse_env_file_commented_line tests/utils_test.py::UtilsTest::test_parse_env_file_invalid_line tests/utils_test.py::UtilsTest::test_parse_env_file_proper tests/utils_test.py::UtilsTest::test_parse_host tests/utils_test.py::UtilsTest::test_parse_host_empty_value tests/utils_test.py::UtilsTest::test_parse_repository_tag tests/utils_test.py::UtilsTest::test_resolve_authconfig tests/utils_test.py::UtilsTest::test_resolve_registry_and_auth tests/utils_test.py::UtilsTest::test_resolve_repository_name tests/utils_test.py::PortsTest::test_build_port_bindings_with_matching_internal_port_ranges tests/utils_test.py::PortsTest::test_build_port_bindings_with_matching_internal_ports tests/utils_test.py::PortsTest::test_build_port_bindings_with_nonmatching_internal_port_ranges tests/utils_test.py::PortsTest::test_build_port_bindings_with_nonmatching_internal_ports tests/utils_test.py::PortsTest::test_build_port_bindings_with_one_port tests/utils_test.py::PortsTest::test_build_port_bindings_with_port_range tests/utils_test.py::PortsTest::test_host_only_with_colon tests/utils_test.py::PortsTest::test_non_matching_length_port_ranges tests/utils_test.py::PortsTest::test_port_and_range_invalid tests/utils_test.py::PortsTest::test_port_only_with_colon tests/utils_test.py::PortsTest::test_split_port_invalid tests/utils_test.py::PortsTest::test_split_port_no_host_port tests/utils_test.py::PortsTest::test_split_port_range_no_host_port tests/utils_test.py::PortsTest::test_split_port_range_with_host_ip_no_port tests/utils_test.py::PortsTest::test_split_port_range_with_host_port tests/utils_test.py::PortsTest::test_split_port_range_with_protocol tests/utils_test.py::PortsTest::test_split_port_with_host_ip tests/utils_test.py::PortsTest::test_split_port_with_host_ip_no_port tests/utils_test.py::PortsTest::test_split_port_with_host_port tests/utils_test.py::PortsTest::test_split_port_with_protocol tests/utils_test.py::ExcludePathsTest::test_directory tests/utils_test.py::ExcludePathsTest::test_directory_with_single_exception tests/utils_test.py::ExcludePathsTest::test_directory_with_subdir_exception tests/utils_test.py::ExcludePathsTest::test_directory_with_trailing_slash tests/utils_test.py::ExcludePathsTest::test_directory_with_wildcard_exception tests/utils_test.py::ExcludePathsTest::test_exclude_custom_dockerfile tests/utils_test.py::ExcludePathsTest::test_exclude_dockerfile_dockerignore tests/utils_test.py::ExcludePathsTest::test_no_dupes tests/utils_test.py::ExcludePathsTest::test_no_excludes tests/utils_test.py::ExcludePathsTest::test_question_mark tests/utils_test.py::ExcludePathsTest::test_single_filename tests/utils_test.py::ExcludePathsTest::test_single_filename_trailing_slash tests/utils_test.py::ExcludePathsTest::test_single_subdir_single_filename tests/utils_test.py::ExcludePathsTest::test_single_subdir_wildcard_filename tests/utils_test.py::ExcludePathsTest::test_subdirectory tests/utils_test.py::ExcludePathsTest::test_wildcard_exclude tests/utils_test.py::ExcludePathsTest::test_wildcard_filename_end tests/utils_test.py::ExcludePathsTest::test_wildcard_filename_start tests/utils_test.py::ExcludePathsTest::test_wildcard_subdir_single_filename tests/utils_test.py::ExcludePathsTest::test_wildcard_subdir_wildcard_filename tests/utils_test.py::ExcludePathsTest::test_wildcard_with_exception tests/utils_test.py::ExcludePathsTest::test_wildcard_with_wildcard_exception
docker/utils/utils.py
docker/utils/utils.py