在Docker容器中运行etcd

时间:2016-02-23 12:40:13

标签: docker etcd

我想使用以下命令在Docker容器中运行etcd

docker run -p 2379:2379 -p 4001:4001 --name etcd -v /usr/share/ca-certificates/:/etc/ssl/certs quay.io/coreos/etcd:v2.3.0-alpha.1

似乎一切正常:

2016-02-23 12:22:27.815591 I | etcdmain: etcd Version: 2.3.0-alpha.0+git
2016-02-23 12:22:27.815631 I | etcdmain: Git SHA: 40d3e0d
2016-02-23 12:22:27.815635 I | etcdmain: Go Version: go1.5.3
2016-02-23 12:22:27.815638 I | etcdmain: Go OS/Arch: linux/amd64
2016-02-23 12:22:27.815659 I | etcdmain: setting maximum number of CPUs to 2, total number of available CPUs is 2
2016-02-23 12:22:27.815663 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd
2016-02-23 12:22:27.815896 I | etcdmain: listening for peers on http://localhost:2380
2016-02-23 12:22:27.815973 I | etcdmain: listening for peers on http://localhost:7001
2016-02-23 12:22:27.816030 I | etcdmain: listening for client requests on http://localhost:2379
2016-02-23 12:22:27.816091 I | etcdmain: listening for client requests on http://localhost:4001
2016-02-23 12:22:27.816370 I | etcdserver: name = default
2016-02-23 12:22:27.816383 I | etcdserver: data dir = default.etcd
2016-02-23 12:22:27.816387 I | etcdserver: member dir = default.etcd/member
2016-02-23 12:22:27.816390 I | etcdserver: heartbeat = 100ms
2016-02-23 12:22:27.816392 I | etcdserver: election = 1000ms
2016-02-23 12:22:27.816395 I | etcdserver: snapshot count = 10000
2016-02-23 12:22:27.816404 I | etcdserver: advertise client URLs = http://localhost:2379,http://localhost:4001
2016-02-23 12:22:27.816408 I | etcdserver: initial advertise peer URLs = http://localhost:2380,http://localhost:7001
2016-02-23 12:22:27.816415 I | etcdserver: initial cluster = default=http://localhost:2380,default=http://localhost:7001
2016-02-23 12:22:27.821522 I | etcdserver: starting member ce2a822cea30bfca in cluster 7e27652122e8b2ae
2016-02-23 12:22:27.821566 I | raft: ce2a822cea30bfca became follower at term 0
2016-02-23 12:22:27.821579 I | raft: newRaft ce2a822cea30bfca [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2016-02-23 12:22:27.821583 I | raft: ce2a822cea30bfca became follower at term 1
2016-02-23 12:22:27.821739 I | etcdserver: starting server... [version: 2.3.0-alpha.0+git, cluster version: to_be_decided]
2016-02-23 12:22:27.822619 N | etcdserver: added local member ce2a822cea30bfca [http://localhost:2380 http://localhost:7001] to cluster 7e27652122e8b2ae
2016-02-23 12:22:28.221880 I | raft: ce2a822cea30bfca is starting a new election at term 1
2016-02-23 12:22:28.222304 I | raft: ce2a822cea30bfca became candidate at term 2
2016-02-23 12:22:28.222545 I | raft: ce2a822cea30bfca received vote from ce2a822cea30bfca at term 2
2016-02-23 12:22:28.222885 I | raft: ce2a822cea30bfca became leader at term 2
2016-02-23 12:22:28.223075 I | raft: raft.node: ce2a822cea30bfca elected leader ce2a822cea30bfca at term 2
2016-02-23 12:22:28.223529 I | etcdserver: setting up the initial cluster version to 2.3
2016-02-23 12:22:28.227050 N | etcdserver: set the initial cluster version to 2.3
2016-02-23 12:22:28.227351 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379 http://localhost:4001]} to cluster 7e27652122e8b2ae

但是当我尝试设置一个密钥(来自相同的etcd节点机器)时:

 curl -L http://localhost:2379/v2/keys/mykey -XPUT -d value="this is awesome"

我明白了:

  

无法检索请求的网址

我是否需要配置更多内容? Docker容器运行正常:

docker ps

dba35d3b61c3  quay.io/coreos/etcd:v2.3.0-alpha.1 "/etcd" 2 seconds ago       Up 1 seconds        0.0.0.0:2379->2379/tcp, 2380/tcp, 0.0.0.0:4001->4001/tcp, 7001/tcp   etcd

1 个答案:

答案 0 :(得分:11)

你应该配置etcd来监听0.0.0.0,否则它会监听127.0.0.1,它不能在docker容器之外访问

docker run \
  -p 2379:2379 \
  -p 4001:4001 \
  --name etcd \
  -v /usr/share/ca-certificates/:/etc/ssl/certs \
  quay.io/coreos/etcd:v2.3.0-alpha.1 \
  -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001