2
2
import ntpath
3
3
from collections import namedtuple
4
4
5
+ from .images import Image
6
+ from .resource import Collection , Model
5
7
from ..api import APIClient
6
8
from ..constants import DEFAULT_DATA_CHUNK_SIZE
7
9
from ..errors import (
8
10
ContainerError , DockerException , ImageNotFound ,
9
11
NotFound , create_unexpected_kwargs_error
10
12
)
11
- from ..types import EndpointConfig , HostConfig , NetworkingConfig
13
+ from ..types import HostConfig , NetworkingConfig
12
14
from ..utils import version_gte
13
- from .images import Image
14
- from .resource import Collection , Model
15
15
16
16
17
17
class Container (Model ):
@@ -21,6 +21,7 @@ class Container(Model):
21
21
query the Docker daemon for the current properties, causing
22
22
:py:attr:`attrs` to be refreshed.
23
23
"""
24
+
24
25
@property
25
26
def name (self ):
26
27
"""
@@ -680,33 +681,13 @@ def run(self, image, command=None, stdout=True, stderr=False,
680
681
This mode is incompatible with ``ports``.
681
682
682
683
Incompatible with ``network``.
683
- network_config (dict): A dictionary containing options that are
684
- passed to the network driver during the connection.
684
+ networking_config (Dict[str, EndpointConfig]):
685
+ Dictionary of EndpointConfig objects for each container network.
686
+ The key is the name of the network.
685
687
Defaults to ``None``.
686
- The dictionary contains the following keys:
687
-
688
- - ``aliases`` (:py:class:`list`): A list of aliases for
689
- the network endpoint.
690
- Names in that list can be used within the network to
691
- reach this container. Defaults to ``None``.
692
- - ``links`` (:py:class:`list`): A list of links for
693
- the network endpoint endpoint.
694
- Containers declared in this list will be linked to this
695
- container. Defaults to ``None``.
696
- - ``ipv4_address`` (str): The IP address to assign to
697
- this container on the network, using the IPv4 protocol.
698
- Defaults to ``None``.
699
- - ``ipv6_address`` (str): The IP address to assign to
700
- this container on the network, using the IPv6 protocol.
701
- Defaults to ``None``.
702
- - ``link_local_ips`` (:py:class:`list`): A list of link-local
703
- (IPv4/IPv6) addresses.
704
- - ``driver_opt`` (dict): A dictionary of options to provide to
705
- the network driver. Defaults to ``None``.
706
- - ``mac_address`` (str): MAC Address to assign to the network
707
- interface. Defaults to ``None``. Requires API >= 1.25.
708
688
709
689
Used in conjuction with ``network``.
690
+
710
691
Incompatible with ``network_mode``.
711
692
oom_kill_disable (bool): Whether to disable OOM killer.
712
693
oom_score_adj (int): An integer value containing the score given
@@ -872,9 +853,9 @@ def run(self, image, command=None, stdout=True, stderr=False,
872
853
'together.'
873
854
)
874
855
875
- if kwargs .get ('network_config ' ) and not kwargs .get ('network' ):
856
+ if kwargs .get ('networking_config ' ) and not kwargs .get ('network' ):
876
857
raise RuntimeError (
877
- 'The option "network_config " can not be used '
858
+ 'The option "networking_config " can not be used '
878
859
'without "network".'
879
860
)
880
861
@@ -1030,6 +1011,7 @@ def list(self, all=False, before=None, filters=None, limit=-1, since=None,
1030
1011
1031
1012
def prune (self , filters = None ):
1032
1013
return self .client .api .prune_containers (filters = filters )
1014
+
1033
1015
prune .__doc__ = APIClient .prune_containers .__doc__
1034
1016
1035
1017
@@ -1124,17 +1106,6 @@ def prune(self, filters=None):
1124
1106
]
1125
1107
1126
1108
1127
- NETWORKING_CONFIG_ARGS = [
1128
- 'aliases' ,
1129
- 'links' ,
1130
- 'ipv4_address' ,
1131
- 'ipv6_address' ,
1132
- 'link_local_ips' ,
1133
- 'driver_opt' ,
1134
- 'mac_address'
1135
- ]
1136
-
1137
-
1138
1109
def _create_container_args (kwargs ):
1139
1110
"""
1140
1111
Convert arguments to create() to arguments to create_container().
@@ -1159,24 +1130,17 @@ def _create_container_args(kwargs):
1159
1130
host_config_kwargs ['binds' ] = volumes
1160
1131
1161
1132
network = kwargs .pop ('network' , None )
1162
- network_config = kwargs .pop ('network_config ' , None )
1133
+ networking_config = kwargs .pop ('networking_config ' , None )
1163
1134
if network :
1164
- endpoint_config = None
1165
-
1166
- if network_config :
1167
- clean_endpoint_args = {}
1168
- for arg_name in NETWORKING_CONFIG_ARGS :
1169
- if arg_name in network_config :
1170
- clean_endpoint_args [arg_name ] = network_config [arg_name ]
1171
-
1172
- if clean_endpoint_args :
1173
- endpoint_config = EndpointConfig (
1174
- host_config_kwargs ['version' ], ** clean_endpoint_args
1175
- )
1135
+ if networking_config :
1136
+ # Sanity check: check if the network is defined in the
1137
+ # networking config dict, otherwise switch to None
1138
+ if network not in networking_config :
1139
+ networking_config = None
1176
1140
1177
1141
create_kwargs ['networking_config' ] = NetworkingConfig (
1178
- { network : endpoint_config }
1179
- ) if endpoint_config else {network : None }
1142
+ networking_config
1143
+ ) if networking_config else {network : None }
1180
1144
host_config_kwargs ['network_mode' ] = network
1181
1145
1182
1146
# All kwargs should have been consumed by this point, so raise
0 commit comments