├── .env ├── README.md └── docker-compose.yml /.env: -------------------------------------------------------------------------------- 1 | COMPOSE_PROJECT_NAME=etcd-cluster 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Etcd - distributed key-value store 2 | 3 | ### Prerequisites 4 | 5 | - Docker 25.0+ 6 | 7 | ### Usage 8 | 9 | $ docker compose pull 10 | [+] Running 3/3 11 | ⠿ etcd-3 Pulled 3.9s 12 | ⠿ etcd-1 Pulled 3.9s 13 | ⠿ etcd-2 Pulled 3.9s 14 | 15 | $ docker compose up -d 16 | [+] Running 7/7 17 | ⠿ Network etcd-cluster_default Created 0.1s 18 | ⠿ Volume "etcd-cluster_etcd3" Created 0.0s 19 | ⠿ Volume "etcd-cluster_etcd1" Created 0.0s 20 | ⠿ Volume "etcd-cluster_etcd2" Created 0.0s 21 | ⠿ Container etcd-cluster-etcd-2-1 Started 0.9s 22 | ⠿ Container etcd-cluster-etcd-3-1 Started 1.1s 23 | ⠿ Container etcd-cluster-etcd-1-1 Started 1.1s 24 | 25 | $ docker exec -it etcd-cluster-etcd-1-1 etcdctl endpoint health 26 | 127.0.0.1:2379 is healthy: successfully committed proposal: took = 2.560575ms 27 | 28 | $ docker exec -it etcd-cluster-etcd-2-1 etcdctl endpoint health 29 | 127.0.0.1:2379 is healthy: successfully committed proposal: took = 2.622971ms 30 | 31 | $ docker exec -it etcd-cluster-etcd-3-1 etcdctl endpoint health 32 | 127.0.0.1:2379 is healthy: successfully committed proposal: took = 2.561252ms 33 | 34 | # put secret from any one of the etcd container 35 | $ docker exec -it etcd-cluster-etcd-1-1 etcdctl put secret password 36 | OK 37 | 38 | $ docker exec -it etcd-cluster-etcd-1-1 etcdctl get secret 39 | secret 40 | password 41 | 42 | $ docker exec -it etcd-cluster-etcd-2-1 etcdctl get secret 43 | secret 44 | password 45 | 46 | $ docker exec -it etcd-cluster-etcd-3-1 etcdctl get secret 47 | secret 48 | password 49 | 50 | ### Container Images 51 | 52 | - [etcd][etcd-repository] 53 | 54 | [etcd-repository]: https://quay.io/repository/coreos/etcd?tab=tags 55 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | x-variables: 2 | flag_initial_cluster_token: &flag_initial_cluster_token '--initial-cluster-token=mys3cr3ttok3n' 3 | common_settings: &common_settings 4 | image: quay.io/coreos/etcd:v3.5.21 5 | entrypoint: /usr/local/bin/etcd 6 | ports: 7 | - 2379 8 | 9 | services: 10 | etcd-1: 11 | <<: *common_settings 12 | command: 13 | - '--name=etcd-1' 14 | - '--initial-advertise-peer-urls=http://etcd-1:2380' 15 | - '--listen-peer-urls=http://0.0.0.0:2380' 16 | - '--listen-client-urls=http://0.0.0.0:2379' 17 | - '--advertise-client-urls=http://etcd-1:2379' 18 | - '--heartbeat-interval=250' 19 | - '--election-timeout=1250' 20 | - '--initial-cluster=etcd-1=http://etcd-1:2380,etcd-2=http://etcd-2:2380,etcd-3=http://etcd-3:2380' 21 | - '--initial-cluster-state=new' 22 | - *flag_initial_cluster_token 23 | volumes: 24 | - etcd1:/etcd_data 25 | 26 | etcd-2: 27 | <<: *common_settings 28 | command: 29 | - '--name=etcd-2' 30 | - '--initial-advertise-peer-urls=http://etcd-2:2380' 31 | - '--listen-peer-urls=http://0.0.0.0:2380' 32 | - '--listen-client-urls=http://0.0.0.0:2379' 33 | - '--advertise-client-urls=http://etcd-2:2379' 34 | - '--heartbeat-interval=250' 35 | - '--election-timeout=1250' 36 | - '--initial-cluster=etcd-1=http://etcd-1:2380,etcd-2=http://etcd-2:2380,etcd-3=http://etcd-3:2380' 37 | - '--initial-cluster-state=new' 38 | - *flag_initial_cluster_token 39 | volumes: 40 | - etcd2:/etcd_data 41 | 42 | etcd-3: 43 | <<: *common_settings 44 | command: 45 | - '--name=etcd-3' 46 | - '--initial-advertise-peer-urls=http://etcd-3:2380' 47 | - '--listen-peer-urls=http://0.0.0.0:2380' 48 | - '--listen-client-urls=http://0.0.0.0:2379' 49 | - '--advertise-client-urls=http://etcd-3:2379' 50 | - '--heartbeat-interval=250' 51 | - '--election-timeout=1250' 52 | - '--initial-cluster=etcd-1=http://etcd-1:2380,etcd-2=http://etcd-2:2380,etcd-3=http://etcd-3:2380' 53 | - '--initial-cluster-state=new' 54 | - *flag_initial_cluster_token 55 | volumes: 56 | - etcd3:/etcd_data 57 | 58 | volumes: 59 | etcd1: 60 | etcd2: 61 | etcd3: 62 | --------------------------------------------------------------------------------