Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "connection refused" when trying to access etcd from within a Docker container

I am trying to access etcd from within a running Docker container. When I run

curl http://172.17.42.1:4001/v2/keys

I get

curl: (7) Failed to connect to 172.17.42.1 port 4001: Connection refused

I have four other hosts where this works fine, but every container on this machine has this problem. I'm really at a loss as to what's going on, and I don't know how to debug it.

My etcd environment variables are

ETCD_ADVERTISE_CLIENT_URLS=http://10.242.10.2:2379
ETCD_DISCOVERY=https://discovery.etcd.io/<token_removed>
ETCD_INITIAL_ADVERTISE_PEER_URLS=http://10.242.10.2:2380
ETCD_LISTEN_CLIENT_URLS=http://10.242.10.2:2379,http://127.0.0.1:2379,http://0.0.0.0:4001
ETCD_LISTEN_PEER_URLS=http://10.242.10.2:2380

I can also access etcd from the host with

curl http://localhost:4001/v2/keys

So there seems to be some error when routing from the container out to the host. But I can't figure out what it is. Can anyone point me in the right direction?

like image 946
Kris Harper Avatar asked Dec 25 '22 13:12

Kris Harper


1 Answers

I observed I had to use the --advertise-client-urls and --listen-client-urls. Like so:

./etcd --advertise-client-urls 'http://0.0.0.0:2379,http://0.0.0.0:4001' --listen-client-urls 'http://0.0.0.0:2379,http://0.0.0.0:4001'

Then I was able to successfully do

curl -L http://hostname:2379/version

from any machine that could reach that server and it worked.

like image 161
edburns Avatar answered Apr 12 '23 22:04

edburns