Skip to content

Commit 1845d3b

Browse files
committed
Added some type and version checks; removed security_opt from container_config (as this is invalid)
1 parent 24b0cab commit 1845d3b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

docker/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
444444
network_disabled=False, name=None, entrypoint=None,
445445
cpu_shares=None, working_dir=None, domainname=None,
446446
memswap_limit=0, cpuset=None, host_config=None,
447-
mac_address=None, labels=None, security_opt=None):
447+
mac_address=None, labels=None):
448448

449449
if isinstance(volumes, six.string_types):
450450
volumes = [volumes, ]
@@ -458,8 +458,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
458458
self._version, image, command, hostname, user, detach, stdin_open,
459459
tty, mem_limit, ports, environment, dns, volumes, volumes_from,
460460
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
461-
memswap_limit, cpuset, host_config, mac_address, labels,
462-
security_opt
461+
memswap_limit, cpuset, host_config, mac_address, labels
463462
)
464463
return self.create_container_from_config(config, name)
465464

@@ -883,6 +882,12 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
883882
'volumes_from is only supported for API version >= 1.10'
884883
)
885884

885+
if utils.compare_version('1.15', self._version) < 0:
886+
if security_opt is not None:
887+
raise errors.InvalidVersion(
888+
'security_opt is only supported for API version >= 1.15'
889+
)
890+
886891
if utils.compare_version('1.17', self._version) < 0:
887892
if read_only is not None:
888893
raise errors.InvalidVersion(

docker/utils/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ def create_host_config(
395395
host_config['Dns'] = dns
396396

397397
if security_opt is not None:
398+
if not isinstance(security_opt, list):
399+
raise errors.DockerException(
400+
'Invalid type for security_opt param: expected list but found'
401+
' {0}'.format(type(security_opt))
402+
)
398403
host_config['SecurityOpt'] = security_opt
399404

400405
if volumes_from is not None:
@@ -447,7 +452,7 @@ def create_container_config(
447452
dns=None, volumes=None, volumes_from=None, network_disabled=False,
448453
entrypoint=None, cpu_shares=None, working_dir=None, domainname=None,
449454
memswap_limit=0, cpuset=None, host_config=None, mac_address=None,
450-
labels=None, security_opt=None
455+
labels=None
451456
):
452457
if isinstance(command, six.string_types):
453458
command = shlex.split(str(command))
@@ -546,5 +551,4 @@ def create_container_config(
546551
'HostConfig': host_config,
547552
'MacAddress': mac_address,
548553
'Labels': labels,
549-
'SecurityOpt': security_opt,
550554
}

0 commit comments

Comments
 (0)