Docker Community Forums

Share and learn in the Docker community.

Networking Two Compose Stacks - Round Robin Behaviour

I have two Docker compose stacks (v3.3 definition) - and since upgrading the Docker engine to 4.2, when running both stacks and networking using network → default → external → {point it at the network name of stack A in both stacks), requests seem to be round-robinning between the two. Which means 50% of the time, my code executes in the correct place, and the other 50% the request is sent to a stack that doesn’t know how to handle it.

This worked fine before the 4.2 upgrade - but it seems when you have 2 stacks now, the routing is broken.

I have one stack running an nginx and PHP container on 8080 and another on 80;

Can you share an example how your compose files look like? You can delete any parameter from that file except the network names and it would be useful if you could leave hostnames (from the connection strings) in the files.

If your containers use domain names to communicate and you have two stack on the same network, and call the PHP container “php” in each stack, then it is normal to load balance between them.

Since you stated that it worked before Docker Desktop 4.2, the reason can be something else.

it pretty much smells like what Akos wrote: a service name collision in the same network.

If two services/hostnames/containernames with identical name share the same network, in case of docker compose deployments, each will be registered as entry in the multi-value dns response for the same service name, regardless wether they are in the same stack or not. If you realy need to have both stacks on the same external network, they need to have different names OR you you will have to assign unique aliases for the services in each stack and call it by the alias.