MCPcopy Index your code
hub / github.com/docker/docker-py / _create_container_args

Function _create_container_args

docker/models/containers.py:1122–1181  ·  view source on GitHub ↗

Convert arguments to create() to arguments to create_container().

(kwargs)

Source from the content-addressed store, hash-verified

1120
1121
1122def _create_container_args(kwargs):
1123 """
1124 Convert arguments to create() to arguments to create_container().
1125 """
1126 # Copy over kwargs which can be copied directly
1127 create_kwargs = {}
1128 for key in copy.copy(kwargs):
1129 if key in RUN_CREATE_KWARGS:
1130 create_kwargs[key] = kwargs.pop(key)
1131 host_config_kwargs = {}
1132 for key in copy.copy(kwargs):
1133 if key in RUN_HOST_CONFIG_KWARGS:
1134 host_config_kwargs[key] = kwargs.pop(key)
1135
1136 # Process kwargs which are split over both create and host_config
1137 ports = kwargs.pop('ports', {})
1138 if ports:
1139 host_config_kwargs['port_bindings'] = ports
1140
1141 volumes = kwargs.pop('volumes', {})
1142 if volumes:
1143 host_config_kwargs['binds'] = volumes
1144
1145 network = kwargs.pop('network', None)
1146 networking_config = kwargs.pop('networking_config', None)
1147 if network:
1148 if networking_config:
1149 # Sanity check: check if the network is defined in the
1150 # networking config dict, otherwise switch to None
1151 if network not in networking_config:
1152 networking_config = None
1153
1154 create_kwargs['networking_config'] = NetworkingConfig(
1155 networking_config
1156 ) if networking_config else {network: None}
1157 host_config_kwargs['network_mode'] = network
1158
1159 # All kwargs should have been consumed by this point, so raise
1160 # error if any are left
1161 if kwargs:
1162 raise create_unexpected_kwargs_error('run', kwargs)
1163
1164 create_kwargs['host_config'] = HostConfig(**host_config_kwargs)
1165
1166 # Fill in any kwargs which need processing by create_host_config first
1167 port_bindings = create_kwargs['host_config'].get('PortBindings')
1168 if port_bindings:
1169 # sort to make consistent for tests
1170 create_kwargs['ports'] = [tuple(p.split('/', 1))
1171 for p in sorted(port_bindings.keys())]
1172 if volumes:
1173 if isinstance(volumes, dict):
1174 create_kwargs['volumes'] = [
1175 v.get('bind') for v in volumes.values()
1176 ]
1177 else:
1178 create_kwargs['volumes'] = [
1179 _host_volume_from_bind(v) for v in volumes

Callers 2

createMethod · 0.85

Calls 5

NetworkingConfigClass · 0.85
HostConfigClass · 0.85
_host_volume_from_bindFunction · 0.85
getMethod · 0.45

Tested by 1