The order in which networks are assigned to interfaces does not match the order they are listed in compose file #4645
The following report was produced using Docker version 17.03.0-ce and compose version
I would expect the networks to be assigned to interface in order, such that
However, when using
On my system, that produces as output:
For comparison, here is a script that performs the same test using
This always runs without error.
The text was updated successfully, but these errors were encountered:
+1 form me as well.
For example part of my compose looks like this:
Hope this helps someone.
Workaround of setting alphabetically order is not working for me in
In any case, even if alphabetically works, I still need to have the same network assigned to different interfaces in different containers, so still need to force the ordering.
As @johnharris85 mentioned, network configuration is passed to docker engine as an unordered dict if networks are created with the container. One possible implementation would be to first create the container and then connect the container to each network one by one. This behaviour could be also configurable.
I have been playing with the scripts provided by @larsks , and docker engine keeps the order of the interfaces only when networks are connected to a running container. Otherwise, it will also create the interfaces randomly.
If the container is started after connecting the networks, it will also have mismatches
Same happens if container is restarted
Anyway, even if docker engine offers support for this behaviour (this is already adressed: moby/moby#25181), docker-compose won't respect the definition order since original network list is converted to an unordered list.
In addition, if connections include parameters like a fixed ip address, networks is not a list at all, it is implemented as a dictionary. Maybe some additional parameter like order or priority would be needed if docker engine implements this behaviour at some point.
@gentunian after looking at the code, I don't see any difference in handling network priorities between v2 and v3.
however, a rapid test shows that priorities are currently ignored by docker, would you choose v2 or v3... lexical order of network names seems to be overriding the priorities you set. see https://gist.github.com/jfellus/cfee9efc1e8e1baf9d15314f16a46eca
(the answer to this may also answer docker/cli#1372)