@@ -147,7 +147,7 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
147147
148148 Returns:
149149 (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.
151151
152152 Raises:
153153 :py:class:`docker.errors.APIError`
@@ -546,10 +546,12 @@ def run(self, image, command=None, stdout=True, stderr=False,
546546 behavior. Accepts number between 0 and 100.
547547 memswap_limit (str or int): Maximum amount of memory + swap a
548548 container is allowed to consume.
549- networks (:py:class:`list`): A list of network names to connect
550- this container to.
551549 name (str): The name for this container.
552550 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``.
553555 network_disabled (bool): Disable networking.
554556 network_mode (str): One of:
555557
@@ -559,6 +561,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
559561 - ``container:<name|id>`` Reuse another container's network
560562 stack.
561563 - ``host`` Use the host network stack.
564+ Incompatible with ``network``.
562565 oom_kill_disable (bool): Whether to disable OOM killer.
563566 oom_score_adj (int): An integer value containing the score given
564567 to the container in order to tune OOM killer preferences.
@@ -680,6 +683,12 @@ def run(self, image, command=None, stdout=True, stderr=False,
680683 raise RuntimeError ("The options 'detach' and 'remove' cannot be "
681684 "used together." )
682685
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+
683692 try :
684693 container = self .create (image = image , command = command ,
685694 detach = detach , ** kwargs )
@@ -902,10 +911,10 @@ def _create_container_args(kwargs):
902911 if volumes :
903912 host_config_kwargs ['binds' ] = volumes
904913
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
909918
910919 # All kwargs should have been consumed by this point, so raise
911920 # error if any are left
0 commit comments