docker_container: pass networks to Daemon on container creation (#933)

* Pass networks to Daemon on container creation.

* Restore old behavior, and only provide all networks on creation for API 1.44+.
This commit is contained in:
Felix Fontein
2024-07-23 17:34:26 +02:00
committed by GitHub
parent 11ce793f7d
commit 2ddadf1e2b
5 changed files with 50 additions and 6 deletions
@@ -766,12 +766,22 @@ class ContainerManager(DockerBaseClass):
self.log("create container")
self.log("image: %s parameters:" % image)
self.log(create_parameters, pretty_print=True)
self.results['actions'].append(dict(created="Created container", create_parameters=create_parameters))
networks = {}
if self.param_networks_cli_compatible and self.module.params['networks']:
network_list = self.module.params['networks']
if not self.engine_driver.create_container_supports_more_than_one_network(self.client):
network_list = network_list[:1]
for network in network_list:
networks[network['name']] = {
key: value for key, value in network.items()
if key not in ('name', 'id')
}
self.results['actions'].append(dict(created="Created container", create_parameters=create_parameters, networks=networks))
self.results['changed'] = True
new_container = None
if not self.check_mode:
try:
container_id = self.engine_driver.create_container(self.client, self.param_name, create_parameters)
container_id = self.engine_driver.create_container(self.client, self.param_name, create_parameters, networks=networks)
except Exception as exc:
self.fail("Error creating container: %s" % to_native(exc))
return self._get_container(container_id)