The following guide will show you how to run etcd under Docker using the .

In order to expose the etcd API to clients outside of the Docker host you’ll need use the host IP address when configuring etcd.

This will run the latest release version of etcd. You can specify version if needed (e.g. quay.io/coreos/etcd:v2.2.0).

  1. docker run -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \
  2. --name etcd quay.io/coreos/etcd:v2.3.8 \
  3. -name etcd0 \
  4. -advertise-client-urls http://${HostIP}:2379,http://${HostIP}:4001 \
  5. -initial-advertise-peer-urls http://${HostIP}:2380 \
  6. -listen-peer-urls http://0.0.0.0:2380 \
  7. -initial-cluster etcd0=http://${HostIP}:2380 \
  8. -initial-cluster-state new

Configure etcd clients to use the Docker host IP and one of the listening ports from above.

  1. etcdctl -C http://192.168.12.50:4001 member list

Running a 3 node etcd cluster

Although the following commands look very similar, note that -name, -advertise-client-urls and -initial-advertise-peer-urls differ for each cluster member

  1. docker run -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \
  2. -advertise-client-urls http://192.168.12.51:2379,http://192.168.12.51:4001 \
  3. -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
  4. -initial-advertise-peer-urls http://192.168.12.51:2380 \
  5. -listen-peer-urls http://0.0.0.0:2380 \
  6. -initial-cluster-token etcd-cluster-1 \
  7. -initial-cluster etcd0=http://192.168.12.50:2380,etcd1=http://192.168.12.51:2380,etcd2=http://192.168.12.52:2380 \
  8. -initial-cluster-state new

Once the cluster has been bootstrapped etcd clients can be configured with a list of etcd members: