Search code examples
dockergoogle-cloud-platformdocker-composedocker-swarm

Manager not load balancing in Docker


When I access the manager node in MANAGERIP, it doesn't load balance to it's workers, but if I access WORKERIP, they will load balance between themselves and leave manager out.

My docker-compose.yml:

version: "3"
services:
    web:
        image: -
        deploy:
          replicas: 3
          resources:
            limits:
              cpus: "0.5"
          restart_policy:
            condition: on-failure
        ports:
          - "80:80"
          - "8080:80"
        networks:
          - webnet
        volumes:
          - /home/{{ ansible_user }}/.env:/home/opus/.env
          - /home/{{ ansible_user }}/database.php:/home/opus/config/database.php
    networks:
      webnet:

It's a configuration problem? All the nodes are Reachable by manager and all of them are running the container.


Solution

  • The problem was that I could not advertise the external ip to the swarm, so the correct syntax is:

    docker swarm init
        --advertise-addr=**GoogleCloud Machine Internal IP(10.*.*.*)**
    

    The same thing goes for the docker join, the workers should use the manager internal IP.