Repository: docker/docker-py

Issue:
volume_driver isn't recognized as a host config keyword argument when using DockerClient API
#### Bug Description
When using the `DockerClient` API, the `volume_driver` keyword argument isn't being recognized as a host config keyword argument. The issue is also present in `master`.

---

#### Likely Cause
In docker-py release 3.0.0 \[[Link 1][bug_release]\], `volume_driver` was removed as a `APIClient.create_container` keyword argument and was moved to the host configuration. The high-level `DockerClient` API has not been updated in response to this change. \[[Link 2][impl_logic], [Link 3][impl_config]\]

---

#### Steps to Reproduce
<details>
<summary>Code Snippet</summary>

```python
import docker

client = docker.from_env()
client.containers.run(
    image='hello-world',
    command='env',
    volume_driver='nvidia-docker'
)
```

**Note**: It is not necessary for the specified volume driver to be available when attempting to reproduce the bug.

**Output**:
```
Traceback (most recent call last):
  File "~/.PyCharm2018.3/config/scratches/scratch_4.py", line 7, in <module>
    volume_driver='nvidia-docker'
  File "~/.conda/envs/lorem-ipsum/lib/python3.7/site-packages/docker/models/containers.py", line 785, in run
    detach=detach, **kwargs)
  File "~/.conda/envs/lorem-ipsum/lib/python3.7/site-packages/docker/models/containers.py", line 843, in create
    resp = self.client.api.create_container(**create_kwargs)
TypeError: create_container() got an unexpected keyword argument 'volume_driver'
```
</details>

---

#### Fix
At [Link 3][impl_config], move `'volume_driver'` from `RUN_CREATE_KWARGS` to `RUN_HOST_CONFIG_KWARGS`.

#### Temporary Patch

<details>
<summary>Code Snippet</summary>

```python
def _patch_docker_py():
    """
    Patch a bug in docker-py.

    docker-py proposed a breaking change in v3.0.0 and failed to correctly
    implement the change, so 'volume_driver' is processed as a 'create' kwarg
    instead of a 'host config' kwarg.

    Relevant function: docker.models.containers._create_container_args.

    """
    docker.models.containers.RUN_CREATE_KWARGS.remove('volume_driver')
    docker.models.containers.RUN_HOST_CONFIG_KWARGS.append('volume_driver')


_patch_docker_py()
```
</details>

---

#### Environment

OS: Ubuntu 16.04, 64-bit
Docker: 18.03.1-ce
Docker API: 1.37
Python: 3.7.1
docker-py: 3.7.0

[bug_release]: https://github.com/docker/docker-py/releases/tag/3.0.0
[impl_logic]: https://github.com/docker/docker-py/blob/3.7.0/docker/models/containers.py#L1025
[impl_config]: https://github.com/docker/docker-py/blob/3.7.0/docker/models/containers.py#L938


Discussion:

Resolving patch:
diff --git a/docker/models/containers.py b/docker/models/containers.py
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -964,7 +964,6 @@ def prune(self, filters=None):
     'tty',
     'use_config_proxy',
     'user',
-    'volume_driver',
     'working_dir',
 ]
 
@@ -1028,6 +1027,7 @@ def prune(self, filters=None):
     'userns_mode',
     'uts_mode',
     'version',
+    'volume_driver',
     'volumes_from',
     'runtime'
 ]


Test patch:
diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py
--- a/tests/integration/models_containers_test.py
+++ b/tests/integration/models_containers_test.py
@@ -378,3 +378,13 @@ def test_wait(self):
                                           detach=True)
         self.tmp_containers.append(container.id)
         assert container.wait()['StatusCode'] == 1
+
+    def test_create_with_volume_driver(self):
+        client = docker.from_env(version=TEST_API_VERSION)
+        container = client.containers.create(
+            'alpine',
+            'sleep 300',
+            volume_driver='foo'
+        )
+        self.tmp_containers.append(container.id)
+        assert container.attrs['HostConfig']['VolumeDriver'] == 'foo'
diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py
--- a/tests/unit/models_containers_test.py
+++ b/tests/unit/models_containers_test.py
@@ -176,6 +176,7 @@ def test_create_container_args(self):
                 'Ulimits': [{"Name": "nofile", "Soft": 1024, "Hard": 2048}],
                 'UsernsMode': 'host',
                 'UTSMode': 'host',
+                'VolumeDriver': 'some_driver',
                 'VolumesFrom': ['container'],
             },
             healthcheck={'test': 'true'},
@@ -190,7 +191,6 @@ def test_create_container_args(self):
             stop_signal=9,
             tty=True,
             user='bob',
-            volume_driver='some_driver',
             volumes=[
                 '/mnt/vol2',
                 '/mnt/vol1',