mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-09-12 19:07:24 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user