Skip to content

Conversation

@Pnkcaht
Copy link

@Pnkcaht Pnkcaht commented Jan 14, 2026

What I did

Adjusted how NetworkingConfig.EndpointsConfig is built so that networks are ordered by gw_priority before being sent to the Docker Engine.

Previously, even when gw_priority was defined in the Compose file, the order of endpoints passed to the Engine was non-deterministic due to map iteration.
This change ensures endpoints are explicitly ordered by descending gw_priority, matching the expected Compose semantics and Docker Engine behavior.

A helper function was introduced in defaultNetworkSettings to sort endpoint settings before constructing NetworkingConfig, and a unit test was added to validate the ordering.

Related issue

Fixes #13511

(not mandatory) A picture of a cute animal, if possible in relation to what you did

🐳 Carefully routing containers through the right gateway

Notes

  • No behavior change for single-network services
  • Only affects multi-network services with gw_priority configured
  • Covered by unit test

@Pnkcaht Pnkcaht force-pushed the fix-gw-priority-network-order branch 2 times, most recently from 28d7e90 to 1e3fc17 Compare January 14, 2026 23:54
Copy link
Contributor

@ndeloof ndeloof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orderEndpointsByGwPriority returns a map, so won't fix any ordering issue
Also, AFAIK there's no ordering requirements after the priority attribute has been introduced - this was non determinist before this API change, without any workaround.
Is this PR related to an identified issue or just a tentative fix exploring the codebase?

@Pnkcaht Pnkcaht force-pushed the fix-gw-priority-network-order branch from 3f95255 to b73e3fe Compare January 15, 2026 18:11
@Pnkcaht
Copy link
Author

Pnkcaht commented Jan 15, 2026

What changed

Hi again @ndeloof , I made the changes based on your request. 👍
This PR removes any reliance on endpoint ordering when handling gw_priority.

EndpointsConfig is a map and does not guarantee ordering, so using its order to infer gateway priority was incorrect. The logic was updated to use gw_priority only to select the primary network (NetworkMode), without assuming any deterministic order for network endpoints.

The networking configuration now treats endpoint ordering as undefined and only asserts the intended semantic behavior.

Tests

  • Added coverage to ensure gw_priority affects only primary network selection
  • Assert that all expected endpoints are present, without relying on order
  • Validate that the selected NetworkMode matches the network with the lowest gw_priority
image

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.

[BUG] gw_priority is ignored on ipv4 network if service also joins an ipv6 network without priority

2 participants