Run a third container mounting the docker socket, that listens to network connect and network disconnect events.
If containers are connected to a network, connect the load balancer to the network.
If the only container still attached to a network is the load balancer, disconnect it from the network.