使用官方示例
bash
etcd:
image: bitnami/etcd:3.4.15
restart: always
volumes:
- ./etcd_data:/bitnami/etcd
environment:
ALLOW_NONE_AUTHENTICATION: "yes"
ETCD_ADVERTISE_CLIENT_URLS: "http://etcd:2379"
ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
ports:
- "2379:2379/tcp"
networks:
docker:
备份
ETCDCTL_API=3 docker exec -it etcd etcdctl --endpoints=":2379" snapshot save "/bitnami/etcd/snapshot.db"
这时snapshot.db文件在./etcd_data下面,可以复制到对应宿主机上的etcd映射目录下
恢复
bash
1
docker docker exec -it api-etcd-1 bash
2
etcdctl snapshot restore /bitnami/etcd/snapshot.db --data-dir /bitnami/etcd/new_data
3
退出变更配置,指定新的数据目录 - ./etcd_data/new_data:/bitnami/etcd/data
4
重新启动服务