« Back to home

Testing etcd on Docker

Posted on

I was messing around with etcd today on docker. Etcd has some simple instructions for setting up a cluster, but some minor tweaks are needed when you run etcd inside a docker container.

Within a docker container, the loopback address doesn’t connect back to the host. Instead you need to determine address that docker configures for the docker host. On my system the host IP is, but it seems that is not guaranteed. To check your system execute ip route, look for the docker line, the host address should be at the end of that line, or simply execute the following command:

ip route | grep docker | awk '{ print $NF }'

Once you have the docker host address, you can use it to configure and launch your etcd containers. I found it useful to launch them in seperate terminal windows.

# launch machine 1 at ports 4001 and 7001
docker run -p 4001:4001 -p 7001:7001 coreos/etcd -name machine1 -addr -peer-addr

# launch machine 2 at ports 4002 and 7002
docker run -p 4002:4002 -p 7002:7002 coreos/etcd -name machine2 -addr -peer-addr -peers, 

# launch machine 3 at ports 4003 and 7003
docker run -p 4003:4003 -p 7003:7003 coreos/etcd -name machine3 -addr -peer-addr -peers,

Etcd uses the loopback as the default address, so we need to override that with the docker host address. Also, the coreos/etcd dockerfile is configured with an ENTRYPOINT, so command line arguments after the image name are passed to the etcd process.

Once you have your etcd containers running, test it with curl. On the host you can use or your docker host address (

# write the value to machine 1
curl -L -XPUT -d value="testing etcd in docker cluster."

# read the value from machine 1
curl -L

# read the value from machine 2
curl -L

# read the value from machine 3
curl -L

# read the value from machine 3 using host address
curl -L


Etcd was pretty easy to get running and I really like the http interface. As of this writing, the coreos/etcd image is at version 0.4.6 – the etcd team is actively working on 0.5 and they have a warning for anyone that wants to use etcd in production.


comments powered by Disqus