gobetween icon indicating copy to clipboard operation
gobetween copied to clipboard

Can't find backend servers using docker discovery

Open Stayer opened this issue 5 years ago • 4 comments

Hi! Here is my compose-file:

version: "3.7"
services:
    www:
        image: aikain/simplehttpserver:0.1
        volumes:
            - ./1:/var/www:ro
        labels:
            - api=true
    balancer:
        image: yyyar/gobetween
        ports: 
            - 5555:5555
        volumes:
            - ./gobetween.toml:/etc/gobetween/conf/gobetween.toml

and gobetween.toml

[logging]
level = "debug" 
output = "stdout"
format = "text"

[servers.sample]
protocol = "tcp"
bind = "0.0.0.0:5555"
balance = "weight"

  [servers.sample.discovery]
  kind = "docker"
  interval = "10s"
  timeout = "2s"
  docker_endpoint = "unix:///var/run/docker.sock"
  docker_container_private_port = 80
  docker_container_label = "api=true"

  [servers.sample.healthcheck]
  fails = 1
  passes = 1
  interval = "2s"
  timeout = "1s"
  kind = "ping"

I'm running it with docker-compose up --scale www=5 and all www-services works OK and listening for 80 port. Gobetween trying to fetch API, but there is no results....

balancer_1  | 2020-01-25 22:39:10 [INFO ] (dockerFetch): Fetching unix:///var/run/docker.sock api=true 80
balancer_1  | 2020-01-25 22:39:20 [INFO ] (dockerFetch): Fetching unix:///var/run/docker.sock api=true 80
balancer_1  | 2020-01-25 22:39:30 [INFO ] (dockerFetch): Fetching unix:///var/run/docker.sock api=true 80
balancer_1  | 2020-01-25 22:39:40 [INFO ] (dockerFetch): Fetching unix:///var/run/docker.sock api=true 80

I tried with unix/tcp socket, with and without labels, different label names, but it doesn't up

Stayer avatar Jan 25 '20 22:01 Stayer

Using binding docker_endpoint for external IP solves my problem, but with .sock it is still not working

Stayer avatar Jan 26 '20 09:01 Stayer

Hello ,@Stayer . I did not see that you are passing docker endpoint into the container, so your GB tried to reach socket that are not precent inside the gb container i'm not using compose every day but you should add volume section for GB container to pass socket to the GB container

something like:

volumes:
     - /var/run/docker.sock:/var/run/docker.sock 

nickdoikov avatar Jan 26 '20 20:01 nickdoikov

Hello ,@Stayer . I did not see that you are passing docker endpoint into the container, so your GB tried to reach socket that are not precent inside the gb container i'm not using compose every day but you should add volume section for GB container to pass socket to the GB container

something like:

volumes:
     - /var/run/docker.sock:/var/run/docker.sock 

yes, sure, I tried that. On Linux and Windows

there are logs:

2020-02-06 19:39:34 [INFO ] (healthcheck/worker): Sending to scheduler: {{ 0} false}
2020-02-06 19:39:44 [INFO ] (dockerFetch): Fetching unix:///var/run/docker.sock balance=true 7090
2020-02-06 19:40:03 [ERROR] (server.handle [0.0.0.0:7090]): Can't elect backend, Backends empty; Closing connection: 10.0.0.3:43764

this happend in docker swarm and docker-compose

Stayer avatar Feb 06 '20 19:02 Stayer

I have same issue.

Seems that gobetween doesn't try to pick the ip address from docker endpoint. It searches in pubished ports, and picks the one whose address is not '0.0.0.0' for backend. ( maybe pick a address from Networks.IPAddress is a better idea? ) https://github.com/yyyar/gobetween/blob/80c57da4b0b222c9f08f9d8af0972ac8e4ac2208/src/discovery/docker.go#L120-L171

Here is a dirty solution I use.

version: "3.7"
services:
    www:
        image: aikain/simplehttpserver:0.1
        volumes:
            - ./1:/var/www:ro
        labels:
            - api=true
        ports:
            - 127.0.0.1:0:80 # bind to 127.0.0.1:<random_port>
    balancer:
        image: yyyar/gobetween
        network_mode: host # so gobetween can reach 127.0.0.1:<random_port> 
        ports: 
            - 5555:5555
        volumes:
            - ./gobetween.toml:/etc/gobetween/conf/gobetween.toml

liumuqing avatar Oct 09 '22 09:10 liumuqing