Repository: docker/docker-py

Issue:
Add support for storage opts in `container_create`
Since Docker 1.12 (after [this pull request](https://github.com/docker/docker/pull/19367) was merged)
it is possible to pass `--storage-opt size=<size>` to `docker create` in order to set the size of the root filesystem of a container.

As far as I can tell this feature is not yet available in `docker-py` (I have grepped the docs and looked at the arguments of [`create_host_config`](https://github.com/docker/docker-py/blob/master/docker/utils/utils.py#L624) and [`create_container_config`](https://github.com/docker/docker-py/blob/master/docker/utils/utils.py#L1033))

Will this feature be added at some point / would anyone be available to answer questions about a possible implementation?


Discussion:
Second for this feature.

Resolving patch:
diff --git a/docker/api/container.py b/docker/api/container.py
--- a/docker/api/container.py
+++ b/docker/api/container.py
@@ -547,6 +547,8 @@ def create_host_config(self, *args, **kwargs):
             security_opt (:py:class:`list`): A list of string values to
                 customize labels for MLS systems, such as SELinux.
             shm_size (str or int): Size of /dev/shm (e.g. ``1G``).
+            storage_opt (dict): Storage driver options per container as a
+                key-value mapping.
             sysctls (dict): Kernel parameters to set in the container.
             tmpfs (dict): Temporary filesystems to mount, as a dictionary
                 mapping a path inside the container to options for that path.
diff --git a/docker/models/containers.py b/docker/models/containers.py
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -585,6 +585,8 @@ def run(self, image, command=None, stdout=True, stderr=False,
                 Default: ``False``.
             stop_signal (str): The stop signal to use to stop the container
                 (e.g. ``SIGINT``).
+            storage_opt (dict): Storage driver options per container as a
+                key-value mapping.
             sysctls (dict): Kernel parameters to set in the container.
             tmpfs (dict): Temporary filesystems to mount, as a dictionary
                 mapping a path inside the container to options for that path.
@@ -828,6 +830,7 @@ def list(self, all=False, before=None, filters=None, limit=-1, since=None):
     'restart_policy',
     'security_opt',
     'shm_size',
+    'storage_opt',
     'sysctls',
     'tmpfs',
     'ulimits',
diff --git a/docker/types/containers.py b/docker/types/containers.py
--- a/docker/types/containers.py
+++ b/docker/types/containers.py
@@ -117,7 +117,7 @@ def __init__(self, version, binds=None, port_bindings=None,
                  oom_kill_disable=False, shm_size=None, sysctls=None,
                  tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None,
                  cpuset_cpus=None, userns_mode=None, pids_limit=None,
-                 isolation=None, auto_remove=False):
+                 isolation=None, auto_remove=False, storage_opt=None):
 
         if mem_limit is not None:
             self['Memory'] = parse_bytes(mem_limit)
@@ -412,6 +412,11 @@ def __init__(self, version, binds=None, port_bindings=None,
                 raise host_config_version_error('auto_remove', '1.25')
             self['AutoRemove'] = auto_remove
 
+        if storage_opt is not None:
+            if version_lt(version, '1.24'):
+                raise host_config_version_error('storage_opt', '1.24')
+            self['StorageOpt'] = storage_opt
+
 
 def host_config_type_error(param, param_value, expected):
     error_msg = 'Invalid type for {0} param: expected {1} but found {2}'


Test patch:
diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py
--- a/tests/integration/api_container_test.py
+++ b/tests/integration/api_container_test.py
@@ -422,6 +422,22 @@ def test_create_with_stop_timeout(self):
         config = self.client.inspect_container(container)
         assert config['Config']['StopTimeout'] == 25
 
+    @requires_api_version('1.24')
+    def test_create_with_storage_opt(self):
+        if self.client.info()['Driver'] == 'aufs':
+            return pytest.skip('Not supported on AUFS')
+        host_config = self.client.create_host_config(
+            storage_opt={'size': '120G'}
+        )
+        container = self.client.create_container(
+            BUSYBOX, ['echo', 'test'], host_config=host_config
+        )
+        self.tmp_containers.append(container)
+        config = self.client.inspect_container(container)
+        assert config['HostConfig']['StorageOpt'] == {
+            'size': '120G'
+        }
+
 
 class VolumeBindTest(BaseAPIIntegrationTest):
     def setUp(self):
diff --git a/tests/integration/base.py b/tests/integration/base.py
--- a/tests/integration/base.py
+++ b/tests/integration/base.py
@@ -68,6 +68,10 @@ def setUp(self):
             version=TEST_API_VERSION, timeout=60, **kwargs_from_env()
         )
 
+    def tearDown(self):
+        super(BaseAPIIntegrationTest, self).tearDown()
+        self.client.close()
+
     def run_container(self, *args, **kwargs):
         container = self.client.create_container(*args, **kwargs)
         self.tmp_containers.append(container)