【问题标题】:How to access etcd in docker如何在docker中访问etcd
【发布时间】:2018-05-24 15:21:51
【问题描述】:

我创建了一个容器

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

并使用

 docker exec 40cc9457f132 ifconfig

获取其IP“172.17.0.2”

然后我使用本地etcdctl获取数据,

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

但失败:

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

我该怎么办?

PS: 为了确保数据实际存储在容器中,我先停止了本地 etcd。

systemctl stop etcd

如果我不这样做,我可以得到数据,但它与结果不一样

docker exec 40cc9457f132 etcdctl get /testdir/testkey1

“40cc9457f132”是容器id。

【问题讨论】:

    标签: docker etcd


    【解决方案1】:

    好的,我修好了。是版本的问题。 我本地的etcd是v2.2.4(apt install安装的),etcd镜像版本是v3.0.4。

    我将它们都更新到 v3.3.5 并设置 $ETCDCTL_API=3。 现在好像没事了。

    【讨论】:

      【解决方案2】:

      似乎同一个端口同时使用 localhost 和 docker 容器。 请为容器分配另一个端口。例如 2379->2380

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

      【讨论】:

      • 谢谢。但我认为他们的IP是不同的。 localhost 是 http://127.0.0.1:2379,docker 容器是 http://172.17.0.2:2379。我错了吗?
      • 是的,docker 容器将使用另一个端口。所以你连接localhost:xxxx。您无法连接到其他计算机上的172.17.0.2:2379。因为,docker ip (172.17.0.2) 是 nat ip。
      • 在yml文件中,放一个端口映射。端口:-“2380:2379”#Port etcd
      猜你喜欢
      • 2018-05-28
      • 2015-09-15
      • 1970-01-01
      • 2017-06-14
      • 2019-11-29
      • 2023-02-10
      • 2017-11-21
      • 2020-04-05
      • 1970-01-01
      相关资源
      最近更新 更多