-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
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], 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, Link 3]
Steps to Reproduce
Code Snippet
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'
Fix
At Link 3, move 'volume_driver'
from RUN_CREATE_KWARGS
to RUN_HOST_CONFIG_KWARGS
.
Temporary Patch
Code Snippet
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()
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
Metadata
Metadata
Assignees
Labels
No labels