Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_container: pass networks to Daemon on container creation #933

Merged

Conversation

felixfontein
Copy link
Collaborator

SUMMARY

This works around moby/moby#48192 at least during container creation. When later updating the networks it doesn't help, unfortunately.

Ref: https://forum.ansible.com/t/setting-a-mac-address-in-a-docker-container/7315/6

ISSUE TYPE
  • Bugfix Pull Request
  • Feature Pull Request
COMPONENT NAME

docker_container

@felixfontein felixfontein marked this pull request as draft July 19, 2024 08:28
@felixfontein
Copy link
Collaborator Author

This seems to fail when passing more than one network. When looking at how Docker SDK for Python does this, it explicitly says

        You can specify networks to connect the container to by using the
        ``networking_config`` parameter. At the time of creation, you can
        only connect a container to a single networking, but you
        can create more connections by using
        :py:meth:`~connect_container_to_network`.

which kind of reminds me on that I was looking into this before. In fact, check out ansible/ansible@4fac91b#diff-5e7c531fbb5041f2e04c666990379baac0186369a2bf47fa6df4310c92365b9aR1287. This part of the code apparently got lost when switching to talking to the API directly (77e63e2).

Even if we change back to that, it means that only one of the multiple networks will get specified on creation, and the others are attached later on. Which apparently does not result in the MAC address being used. But then, Compose can still do it for more than one network. So there's more work to do to figure out what's happening there...

@felixfontein
Copy link
Collaborator Author

Ah, I found a comment in Compose's sources:

	// Starting from API version 1.44, the Engine will take several EndpointsConfigs
	// so we can pass all the extra networks we want the container to be connected to
	// in the network configuration instead of connecting the container to each extra
	// network individually after creation.

I guess that's the trick then... (For API version < 1.44, it simply passes on the first network if networks are provided for a service, or the default network.)

@felixfontein felixfontein force-pushed the docker_container-mac branch from 4403846 to 00fb562 Compare July 20, 2024 06:43
@felixfontein felixfontein force-pushed the docker_container-mac branch from 00fb562 to 1761cbf Compare July 20, 2024 06:46
@felixfontein felixfontein marked this pull request as ready for review July 20, 2024 08:04
@felixfontein felixfontein merged commit 2ddadf1 into ansible-collections:main Jul 23, 2024
127 checks passed
@felixfontein felixfontein deleted the docker_container-mac branch July 23, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant