buraksezer / olric

Distributed, in-memory key/value store and cache. It can be used as an embedded Go library and a language-independent service.
Apache License 2.0
3.16k stars 119 forks source link

Olric in docker container - memberlist "no private IP address found, and explicit IP not provided" #35

Closed justinfx closed 2 years ago

justinfx commented 4 years ago

I'm looking to see if you have encountered the following issue while trying to run Olric in a container:

docker run -p 3320:3320 olricio/olricd:latest
Olric quits prematurely:
no private IP address found, and explicit IP not provided

Search a bit, this issue implies its a factor of the memberlist library and its gossip protocol, in trying to choose a private ip: https://github.com/thanos-io/thanos/issues/615

And I believe it may have to do with how my docker configuration is set up. If I run it with --net=host then it starts:

docker run --net=host -p 3320:3320 olricio/olricd:latest

So my questions are:

  1. Is this something you have encountered?
  2. Is this something where you have tips that can be added to the documentation?
justinfx commented 4 years ago

It seems its specifically related to how we configure our docker network at my studio vs a default installation, to deal with the potential for conflicts with the external network. So maybe this is just a matter of documenting the situation.

buraksezer commented 4 years ago

Thank you for informing me. I'm going to take a look at thanos#615. Could you please give more information about your setup? Thus, I can provide the problem on my side.

justinfx commented 4 years ago

I have a reproduction for you.

docker network create --subnet=169.254.0.0/16 testnet

docker run -it --network testnet --ip 169.254.0.128 --rm -p 3320:3320 olricio/olricd:latest
# Olric quits prematurely:
# no private IP address found, and explicit IP not provided

docker network rm testnet

This replicates how my studio has custom network settings for their docker deployment to deal with known issues like address collisions, etc. But in this case the hashicorp memberlist isn't happy with the private ip range.

d1ngd0 commented 3 years ago

Hey, Sorry for pulling this one up again, but I am currently experiencing an issue myself. It looks like this line

    privateIfs, _, err = IfByRFC("6890", privateIfs)

inside vendor/github.com/hashicorp/go-sockaddr/ifaddrs.go is forcing all ip addresses to be within RFC 6890 which is likely too narrow. Would it make sense to simply first look into the private addresses, and if nothing is found look into the public ones?

    if bindIP == "0.0.0.0" {
        // if we're not bound to a specific IP, let's use a suitable private IP address.
        ipStr, err := sockaddr.GetPrivateIP()
        if err != nil {
            return "", fmt.Errorf("failed to get interface addresses: %w", err)
        }
        if ipStr == "" {
                // Add logic here to search public ip addresses for bind address.
            return "", fmt.Errorf("no private IP address found, and explicit IP not provided")
        }

        parsed := net.ParseIP(ipStr)
        if parsed == nil {
            return "", fmt.Errorf("failed to parse private IP address: %q", ipStr)
        }
        bindIP = parsed.String()
    }

For instance my IP is within this range but you can see the Source is set to false, which is defined here. I'd be happy to write something up for you if you feel this is the correct direction. Otherwise if you have other ideas I would be willing to implement them too :)

d1ngd0 commented 3 years ago

BTW: The workaround for this is to specify the interface in both the olric section of the config as well as the memberlist. When specifying the interface it looks like olric doesn't care what the ip address is.

buraksezer commented 2 years ago

Hi @d1ngd0

Firstly, I'm so sorry for my late response.

When specifying the interface it looks like olric doesn't care what the ip address is.

Yes it is. Olric tries to discover the IP address from the network interface, if it is defined in the config.

I'd be happy to write something up for you if you feel this is the correct direction. Otherwise if you have other ideas I would be willing to implement them too :)

Great! I would like to see your solution and discuss about it.

justinfx commented 2 years ago

This does work for me now, with the 0.4.4 release