JenningsMao
JenningsMao

Reputation: 21

How to access etcd in docker

I create a container by

docker run  -d --name etcd \
-v /usr/share/ca-certificates/:/etc/ssl/certs \ 
quay.io/coreos/etcd:v3.0.4 /usr/local/bin/etcd -advertise-client-urls \ 
http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379

And use

 docker exec 40cc9457f132 ifconfig

to get its IP "172.17.0.2"

And then I use local etcdctl to get data,

 etcdctl --endpoint=http://172.17.0.2:2379 get /testdir/testkey1

but fail with:

Error:  client: etcd cluster is unavailable or misconfigured
error #0: dial tcp 0.0.0.0:2379: getsockopt: connection refused

What should I do?

PS: To make sure the data is actually stored on the container, I stoped local etcd first.

systemctl stop etcd

If I don't do that, I could get the data, but it's not the same with the result of

docker exec 40cc9457f132 etcdctl get /testdir/testkey1

"40cc9457f132 " is the container id.

Upvotes: 0

Views: 3637

Answers (2)

JenningsMao
JenningsMao

Reputation: 21

OK, I fix it. It's the problem of version. My local etcd is v2.2.4 (installed by apt install), and the etcd image version is v3.0.4.

I update both of them to v3.3.5 and set $ETCDCTL_API=3. Now it seems all right.

Upvotes: 1

Eric Lee
Eric Lee

Reputation: 54

It seems that same port use both localhost and docker container. please assign another port for container. example 2379->2380

etcdctl --endpoint=http://localhost:2379 -> localhost
etcdctl --endpoint=http://localhost:2380 -> docker container

Upvotes: 0

Related Questions