使用docker-compose部署etcd

1、环境

  • 操作系统:Centos 7
  • docker版本:19.03.7
  • docker-compose版本:1.24.0
  • etcd 镜像版本: quay.io/coreos/etcd:v3.4.7

2、拉取官方镜像

$ docker pull quay.io/coreos/etcd:v3.4.7

3、docker-compose.yml 配置文件

version: "3"

services:
  etcd:
    image: quay.io/coreos/etcd:v3.4.7
    container_name: etcd
    ports:
      - 2379:2379
      - 2380:2380
    restart: always
    volumes:
      - data_volume:/etcd-data
    environment:
      - NODE1=192.168.3.233
      - ETCDCTL_API=3
    command:
      - /usr/local/bin/etcd
      - --data-dir=/etcd-data
      - --name
      - node1
      - --initial-advertise-peer-urls
      - http://${NODE1}:2380
      - --listen-peer-urls
      - http://0.0.0.0:2380
      - --advertise-client-urls
      - http://${NODE1}:2379
      - --listen-client-urls
      - http://0.0.0.0:2379
      - --initial-cluster
      - node1=http://${NODE1}:2380

volumes:
  data_volume:

4、后台运行etcd服务

$ docker-compose up -d

5、列出集群成员

$ docker exec -t etcd etcdctl member list
16ff5b66a1ccde72, started, node1, http://192.168.3.233:2380, http://192.168.3.233:2379, false

6、查看etcd及etcdctl版本

$ docker exec -t etcd etcd --version
etcd Version: 3.4.7
Git SHA: e694b7bb0
Go Version: go1.12.17
Go OS/Arch: linux/amd64

$ docker exec -t etcd etcdctl version
etcdctl version: 3.4.7
API version: 3.4

参考链接

官网:Run etcd clusters inside containers
docker-compose 部署 etcd

你可能感兴趣的:(docker,和,docker,compose)