Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
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.
+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.
referenced this issue
Mar 31, 2018
This was referenced
Sep 12, 2018
Swarm features should be requested on the Swarm repo or Moby repo.