Unable to bind consul client_addr to loopback alias with docker installation

I get the following errors:

[ERROR] agent: Error starting agent: error="2 errors occurred:

* listen udp 169.254.1.1:8600: bind: cannot assign requested address

* listen tcp 169.254.1.1:8600: bind: cannot assign requested address

Consul config:

client_addr = "169.254.1.1"
bind_addr = "169.254.1.1"

Consul setup using docker:

docker run -d --name=consul-server -p 8300:8300 -p 8301:8301 -p 8301:8301/udp \
    -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 53:8600 -p 53:8600/udp \
    -v $(pwd)/consul/consul-config:/consul/config consul:latest agent -server \
    -config-dir=/consul/config -grpc-port 8502 -bootstrap-expect 1 -ui

loopback alias

sudo ifconfig lo0 alias 169.254.1.1

Docker IP addresses are dynamic and NAT-ed, you shouldn’t be binding to them directly.
Bind to 0.0.0.0 in the configuration.

@agarwal-nitesh, Consul expects the IP address to already be present on the interface when the process starts. Based on the error you’ve provided, it seems like the IP has not yet been configured.

Can you provide a bit more information as to how you are configuring this IP within the Docker container before starting the Consul process?

Thanks.

Yeah, I get it, I missed a key thing here. But, I have tried this with multiple configurations other than the one mentioned in the issue. I have tried with the host network as well. Basically, what I want to do is to be able to use .service.consul: for services bound to the alias IP (169.254.1.1) or dummy network interface in the case of linux, rather than the network interface. With consul running inside a container.