@@ -147,7 +147,7 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
147
147
148
148
Returns:
149
149
(generator or str): If ``stream=True``, a generator yielding
150
- response chunks. A string containing response data otherwise.
150
+ response chunks. A string containing response data otherwise.
151
151
152
152
Raises:
153
153
:py:class:`docker.errors.APIError`
@@ -546,10 +546,12 @@ def run(self, image, command=None, stdout=True, stderr=False,
546
546
behavior. Accepts number between 0 and 100.
547
547
memswap_limit (str or int): Maximum amount of memory + swap a
548
548
container is allowed to consume.
549
- networks (:py:class:`list`): A list of network names to connect
550
- this container to.
551
549
name (str): The name for this container.
552
550
nano_cpus (int): CPU quota in units of 10-9 CPUs.
551
+ network (str): Name of the network this container will be connected
552
+ to at creation time. You can connect to additional networks
553
+ using :py:meth:`Network.connect`. Incompatible with
554
+ ``network_mode``.
553
555
network_disabled (bool): Disable networking.
554
556
network_mode (str): One of:
555
557
@@ -559,6 +561,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
559
561
- ``container:<name|id>`` Reuse another container's network
560
562
stack.
561
563
- ``host`` Use the host network stack.
564
+ Incompatible with ``network``.
562
565
oom_kill_disable (bool): Whether to disable OOM killer.
563
566
oom_score_adj (int): An integer value containing the score given
564
567
to the container in order to tune OOM killer preferences.
@@ -680,6 +683,12 @@ def run(self, image, command=None, stdout=True, stderr=False,
680
683
raise RuntimeError ("The options 'detach' and 'remove' cannot be "
681
684
"used together." )
682
685
686
+ if kwargs .get ('network' ) and kwargs .get ('network_mode' ):
687
+ raise RuntimeError (
688
+ 'The options "network" and "network_mode" can not be used '
689
+ 'together.'
690
+ )
691
+
683
692
try :
684
693
container = self .create (image = image , command = command ,
685
694
detach = detach , ** kwargs )
@@ -902,10 +911,10 @@ def _create_container_args(kwargs):
902
911
if volumes :
903
912
host_config_kwargs ['binds' ] = volumes
904
913
905
- networks = kwargs .pop ('networks ' , [] )
906
- if networks :
907
- create_kwargs ['networking_config' ] = {network : None
908
- for network in networks }
914
+ network = kwargs .pop ('network ' , None )
915
+ if network :
916
+ create_kwargs ['networking_config' ] = {network : None }
917
+ host_config_kwargs [ 'network_mode' ] = network
909
918
910
919
# All kwargs should have been consumed by this point, so raise
911
920
# error if any are left
0 commit comments